Copied to clipboard

uniq

The `uniq` command removes duplicate lines from a sorted file. It can be customized using various options, such as the `-c` option to count the number of occurrences of each repeated line.

Examples

  • Remove duplicate lines from a sorted file: uniq file.txt
  • Count the number of occurrences of each repeated line: uniq -c file.txt
  • Only display duplicated lines: uniq -d file.txt
  • Ignore the first N fields in each line: uniq -f N file.txt
  • Ignore case differences: uniq -i file.txt
  • Only compare the first N characters in each line: uniq -s N file.txt
  • Only display unique lines: uniq -u file.txt

Note: The uniq command only removes duplicate lines from a sorted file. If the file is not sorted, you need to use the sort command to sort the file first, for example, sort file.txt | uniq.