December 2018
Beginner
320 pages
8h 57m
English
The uniq command is used to remove duplicate lines from a sorted file. It requires the duplicate entries to be in the adjacent lines and, hence, it is mostly used in combination with the sort command, which is used to sort the file contents first. The syntax of the uniq command is as follows:
$ sort <filename> | uniq or$ sort -u <filename>
To count duplicate lines in the file, execute the command line, shown as follows :
$ sort <filename> | uniq -c
To display only the entries that are duplicates, execute the command line, shown as follows:
$ sort <filename> | uniq -cd
Read now
Unlock full access