#!/usr/bin/python # Copyright (C) 2012 Jeff Epler # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys # XXX somehow make this smarter so that e.g., du -h works as input val = int sub = lambda a, b: a-b show = lambda v: "%d" % v def read_du(f): if f == "-": f = sys.stdin else: f = open(f) d = {} for line in f: v, k = line.strip().split(None, 1) d[k] = val(v) return d d1 = read_du(sys.argv[1]) if len(sys.argv) > 2: d2 = read_du(sys.argv[2]) else: d2 = read_du('-') while d1: k, v1 = d1.popitem() if k in d2: v2 = d2.pop(k) else: v2 = 0 dv = sub(v2, v1) if dv: print "%s\t%s" % (show(dv), k) while d2: k, v2 = d2.popitem() print "%s\t%s" % (show(dv), k)