uniq和sort配合进行统计排序

在统计多行相同的内容时,可以使用uniq,主要使用以下这个参数:

       -c, --count
              prefix lines by the number of occurrences

把重复出现的行数,添加在行的内容之前。

排序的时候,可以使用sort,主要是以下两个参数:

       -n, --numeric-sort
              compare according to string numerical value
       -r, --reverse
              reverse the result of comparisons

分别是根据数字量来排序和进行反序排序。


另外,uniq常用的参数还有

       -u, --unique
              only print unique lines
用来排除重复;

       -d, --repeated
              only print duplicate lines, one for each group
用来查找重复,配合-c则把重复的次数也输出出来。



版权声明:本文为code_runner原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。