diff bin/uniq_merge.py @ 88:464d2dfb99c9

new
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Tue, 13 Apr 2021 17:02:09 +0000
parents
children f5e2211b50bd
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/uniq_merge.py	Tue Apr 13 17:02:09 2021 +0000
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+# Merge counts by key from the output of "uniq -c" 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
+s={}
+for l in sys.stdin:
+ (i,d)=l.split()
+ i=int(i)
+ if d in s:
+  s[d]+=i
+ else:
+  s[d]=i
+for (d,n) in sorted(s.items(),key=lambda j:j[1],reverse=True):
+ print('%5d\t%s'%(n,d))