给定一个文本文件,其中将有重复的行,如:
this is a line this is a line this is another line this is a line this is yet another line this is yet another line
是否有可能在命令行上打印出每个唯一的行,但按其出现的频率sorting。
即以前的文本的结果将是:
this is a line this is yet another line this is another line
它们分别出现3次,2次和1次。
试试这个:
sort file|uniq -c|sort -rn
编辑:此外,如果你想删除计数器在行的开头只是管sed 's/^\s*[0-9]* \(.*\)$/\1/'
在上述命令。
你可以这样做:
awk '{ a[$0]++ } END {for (i in a) print a[i], i }' | sort -nr 3 this is a line 2 this is yet another line 1 this is another line