Mercurial > hg > cc > cirrus_home
view bin/uniq_merge.py @ 159:c3c3dd60b8a8
demo of slurm usage using cdx2tsv.py
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Wed, 06 Jul 2022 18:07:34 +0100 |
parents | f5e2211b50bd |
children |
line wrap: on
line source
#!/usr/bin/env python3 # Merge counts by key from the output of "uniq -c" (or sus) and sort in descending order # An alternative to sus when the scale is too big for the initial sort, or if uniq -c already does a lot # of the work # Usage: ... | uniq -c | uniq-merge.py import sys from collections import defaultdict s=defaultdict(int) for l in sys.stdin: (i,d)=l.split(maxsplit=1) s[d]+=int(i) for (d,n) in sorted(s.items(),key=lambda j:j[1],reverse=True): sys.stdout.write('%5d\t%s'%(n,d))