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:
-
Basic Usage:
- Removes adjacent duplicate lines from a file.
- Example:
uniq input.txt
-
Count Occurrences:
- Use the
-coption to count occurrences of each unique line. - Example:
uniq -c input.txt
- Use the
-
Show Duplicate Lines:
- Use the
-doption to display only duplicate lines. - Example:
uniq -d input.txt
- Use the
-
Show Unique Lines:
- Use the
-uoption to display only unique lines (lines that appear exactly once). - Example:
uniq -u input.txt
- Use the
-
Ignore Case:
- Use the
-ioption to ignore case when comparing lines. - Example:
uniq -i input.txt
- Use the
-
Skip Fields:
- Use the
-f Noption to skip the first N fields when comparing lines. - Example:
uniq -f 1 input.txt
- Use the
-
Skip Characters:
- Use the
-s Noption to skip the first N characters when comparing lines. - Example:
uniq -s 2 input.txt
- Use the
These options allow for flexible processing of text data, making uniq a powerful tool for data analysis and cleaning tasks.
