Count the most frequent lines in a file
count occurrences of each line linux | sort uniq count frequency | top entries in a list command line | sort | uniq | countsort list.txt | uniq -c | sort -rn | head -n 20Sorts the lines so that identical entries are adjacent, lets uniq -c count the repetitions and sorts the result numerically in descending order. This is the basic pattern behind many analyses, for example of IP lists, error messages or usernames. Any command that produces a list fits in front of the first sort, such as cut or grep -o.
Note: uniq only detects directly consecutive duplicates, which is why the first sort is mandatory.
Also searched as
- count occurrences of each line linux
- sort uniq count frequency
- top entries in a list command line