[英]Sort Unique column in Unix
I have been looking for an answer for a good amount of time but it seems that it hasn't been answered yet. 我一直在寻找答案很长时间,但似乎尚未找到答案。 I do apologize if this question has already been answered. 如果这个问题已经回答,我深表歉意。
So i am trying to sort the number of appearances from each ID from High to Low. 所以我正在尝试从高到低从每个ID排序出现次数。
From the following command: sort -k1,1 File.txt | uniq -c
从以下命令: sort -k1,1 File.txt | uniq -c
sort -k1,1 File.txt | uniq -c
I get this result : sort -k1,1 File.txt | uniq -c
我得到以下结果:
1 21423
3 21447
5 21448
3 21513
1 21584
1 21585
1 21586
The result I want: 我想要的结果:
5 21448
3 21447
3 21513
1 21423
1 21584
1 21585
1 21586
It does sort the second column even though I typed -k1,1
I have tried different parameters and options such as -n
. 即使我键入了-k1,1
它也会对第二列进行排序,尽管我尝试了其他参数和选项,例如-n
。 Any leads would help me a lot. 任何线索都将对我有很大帮助。 Thanks in advance! 提前致谢!
You need to sort the output of uniq -c
: 您需要对uniq -c
的输出进行排序:
... | uniq -c | sort -nr
When you want to sort lines by the count, it doesn't matter how the items were sorted before calling uniq -c
, because the counts will only be known after the call to uniq -c
. 如果要按计数对行进行排序,则在调用uniq -c
之前如何对项目进行排序并不重要,因为仅在调用uniq -c
之后才能知道计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.