使用命令行工具的排序序列重复计数 [英] counting duplicates in a sorted sequence using command line tools

查看:89
本文介绍了使用命令行工具的排序序列重复计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有通过一个日志文件里grep筛选出一组数字的命令(CMD1)。这些数字是
以随机顺序,所以我用那种-gr得到反向排序号码清单。有可能是内重复
这个排序列表。我需要找到在该列表中的每个唯一的编号计数。

有关如如果CMD1的输出是:

  100
100
100
99
99
26
25
24
24

我需要另一个命令,我可以管上面的输出,这样一来,我得到:

  100 3
99 2
26 1
25 1
24 2


解决方案

怎么样;

  $回声100 100 100 99 99 26 25 24 24| TR\\ n|排序| uniq的-c |排序-k2nr | AWK'{printf的(%s%S,$ 2,$ 1)} END {}打印
100 3 99 26 2 1 25 1 24 2

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.

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

解决方案

how about;

$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆