Forrest logo
back to the sort tool

uniq:tldr:f0c2a

uniq: Display number of occurrences of each line along with that line.
$ sort ${filename} | uniq -c
try on your machine

This command performs two functions:

  1. sort ${filename}: This part of the command sorts the contents of the file specified by ${filename} in ascending order. The sort command arranges the lines alphabetically or numerically depending on the data in the file.

  2. uniq -c: This part of the command is used to filter out duplicate lines from the sorted output of the previous command. The uniq command compares adjacent lines and removes repetition, and the -c option is used to prefix each line with the count of occurrences of that line.

Overall, the command sort ${filename} | uniq -c sorts the contents of the file and then provides a count of the occurrences of each unique line in the sorted output.

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