uniq CommandUsed to report or ignore duplicate rows in a file, typically withSortcommand in conjunction with the.
Grammar
Uniq (option) (parameter)
Options
-C or--count: Displays the number of occurrences of the row next to each column;-D or--repeated: Displays only the repeating rows and columns;-f< fields > or--skip-fields=< columns;: Ignores the comparison of the specified field;-s< Character position > or--skip-chars=< character position;: Ignores the comparison of the specified character;-U or--unique: Displays only once in the row and column;-w< character position > or--check-chars=< character position > : Specifies the character to compare.
Parameters
Input file: Specifies the duplicate line file to be removed. If this item is not specified, the data is read from the standard;
Output file: Specifies the output file to be written to when the contents of the duplicate row are to be removed. If you do not specify this option, the content is displayed to the standard output device (display terminal).
Instance
To delete duplicate rows:
Uniq File.txtsort file.txt | Uniqsort-u file.txt
Show only one line:
Uniq-u File.txtsort file.txt | Uniq-u
Count the number of times each line appears in the file:
Sort File.txt | Uniq-c
Find duplicate lines in the file:
Sort File.txt | Uniq-d
Introduction to Linux uniq command usage