Forrest logo
back to the sort tool

uniq:tldr:21d52

uniq: Display number of occurrences of each line, sorted by the most frequent.
$ sort ${filename} | uniq -c | sort -nr
try on your machine

This command performs a series of operations on the contents of the file specified by the variable ${filename}.

  1. sort ${filename}: This command sorts the lines in the file in ascending order. The ${filename} variable represents the name of the file.

  2. uniq -c: This command eliminates adjacent duplicates and displays only unique lines. The -c option also reports the number of occurrences of each unique line.

  3. sort -nr: This final command sorts the lines again, but this time in descending order (-r option) based on the count of occurrences (-n option), which was added by the previous uniq -c command.

In summary, this command sorts the lines in the file, removes duplicate lines, and then sorts the unique lines in descending order of their occurrence count.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the sort tool