使用命令行工具以排序顺序计数重复 [英] counting duplicates in a sorted sequence using command line tools
本文介绍了使用命令行工具以排序顺序计数重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个命令(cmd1),通过日志文件greps过滤掉一组数字。数字是随机顺序的
,所以我使用排序-gr得到一个反向排序的数字列表。在
这个排序列表中可能有重复。我需要找到该列表中每个唯一编号的计数。
I have a command (cmd1) that greps through a log file to filter out a set of numbers. The numbers are in random order, so I use sort -gr to get a reverse sorted list of numbers. There may be duplicates within this sorted list. I need to find the count for each unique number in that list.
如果cmd1的输出是:
For e.g. if the output of cmd1 is:
100
100
100
99
99
26
25
24
24
我需要另一个命令,我可以管道上面的输出,所以,我得到:
I need another command that I can pipe the above output to, so that, I get:
100 3
99 2
26 1
25 1
24 2
推荐答案
如何;
$ echo "100 100 100 99 99 26 25 24 24" | tr " " "\n" | sort | uniq -c | sort -k2nr | awk '{printf("%s %s ",$2,$1)}END{print}'
100 3 99 2 26 1 25 1 24 2
这篇关于使用命令行工具以排序顺序计数重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文