Forrest logo
back to the sort tool

uniq:tldr:99184

uniq: Display only unique lines.
$ sort ${filename} | uniq -u
try on your machine

This command is used to sort the contents of a file named ${filename} and then display only the unique lines. Here is a breakdown of each component:

  • sort: This command is used to sort the lines of a file alphabetically or numerically. In this case, it sorts the contents of the file ${filename}.
  • ${filename}: This is a placeholder for the actual filename. It should be replaced with the name of the file you want to sort and find unique lines from.
  • |: This is called a pipe symbol and is used to connect the output of one command to the input of another command. In this case, it connects the output of the sort command to the input of the uniq command.
  • uniq: This command is used to filter out adjacent repeated lines. It only displays unique lines, discarding any duplicate lines.
  • -u: This is an option flag for the uniq command. It tells uniq to only display lines that are unique, i.e., it excludes any lines that have duplicates.

In summary, the command sort ${filename} | uniq -u will sort the lines of the specified file ${filename} and display only the unique lines, removing any duplicate lines.

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