Forrest logo
back to the sort tool

uniq:tldr:e90e6

uniq: Display each line once.
$ sort ${filename} | uniq
try on your machine

This command is used to sort the contents of a file in alphabetical or numerical order and remove any duplicate lines.

Here's how it works:

  1. ${filename} represents the placeholder for the name of the file you want to sort and remove duplicate lines from. You need to replace ${filename} with the actual file name or its path.
  2. The sort command takes the contents of the specified file and arranges them in ascending order by default. This means that if the file contains text, the lines will be sorted alphabetically; if it contains numbers, they will be sorted in numerical order.
  3. The sorted output from sort is then passed as input to the uniq command.
  4. The uniq command removes duplicated lines from the input it receives. Only the first occurrence of each unique line is kept, and any subsequent repetitions are discarded.
  5. The result of the uniq command is printed to the console.

Overall, using sort ${filename} | uniq allows you to sort the contents of a file and display only the unique lines, discarding any duplicates.

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