Search code examples
bashlines

Find most frequent line in file in bash


Suppose I have a file similar to as follows:

Abigail 85
Kaylee 25
Kaylee 25
kaylee
Brooklyn
Kaylee 25
kaylee 25

I would like to find the most repeated line, the output must be just the line.

I've tried

sort list | uniq -c

but I need clean output, just the most repeated line (in this example Kaylee 25).


Solution

  • Kaizen ~

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

    does this help ?