Find most frequent line in file in bash

核能气质少年 提交于 2019-12-04 07:39:30

Kaizen ~

$ sort zlist | uniq -c | sort -r | head -1|  xargs | cut -d" " -f2-

Kaylee 25

does this help ?

Sina Bahram

IMHO, none of these answers will sort the results correctly. The reason is that sort, without the -n, option will sort like this "1 10 11 2 3 4", etc., instead of "1 2 3 4 10 11 12". So, add -n like so:

sort zlist | uniq -c | sort -n -r | head -1

You can then, of course, pipe that to either xargs or sed as described earlier.

awk -

awk '{a[$0]++; if(m<a[$0]){ m=a[$0];s[m]=$0}} END{print s[m]}' t.lis
$ uniq -c list | sort -r | head -1 | awk '{$1=""}1'

Kaylee 25

Is this what you're looking for?

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!