What are the different functionalities of the 'uniq' command?

The uniq command in Linux is used to filter out duplicate lines in text files. Here are the different functionalities and options of the uniq command:

  1. Basic Usage:

    • Removes adjacent duplicate lines from a file.
    • Example: uniq input.txt
  2. Count Occurrences:

    • Use the -c option to count occurrences of each unique line.
    • Example: uniq -c input.txt
  3. Show Duplicate Lines:

    • Use the -d option to display only duplicate lines.
    • Example: uniq -d input.txt
  4. Show Unique Lines:

    • Use the -u option to display only unique lines (lines that appear exactly once).
    • Example: uniq -u input.txt
  5. Ignore Case:

    • Use the -i option to ignore case when comparing lines.
    • Example: uniq -i input.txt
  6. Skip Fields:

    • Use the -f N option to skip the first N fields when comparing lines.
    • Example: uniq -f 1 input.txt
  7. Skip Characters:

    • Use the -s N option to skip the first N characters when comparing lines.
    • Example: uniq -s 2 input.txt

These options allow for flexible processing of text data, making uniq a powerful tool for data analysis and cleaning tasks.

0 Comments

no data
Be the first to share your comment!