sum and count columns from stdin, because I'm no good at awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
d = {} | |
for line in sys.stdin: | |
adds, dels, path = line.rstrip().split('\t') | |
if path in d: | |
d[path]['adds'] += int(adds) | |
d[path]['dels'] += int(dels) | |
d[path]['count'] += 1 | |
else: | |
d[path] = {'adds': int(adds), 'dels': int(dels), 'count': 1} | |
for path, vals in d.items(): | |
sys.stdout.write(f"{vals['count']}\t{vals['adds']}\t{vals['dels']}\t{path}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment