uniq command in Linux with examples
The linux uniq command is basically used to remove all repeated lines in a file. This command is used when a line is repeated multiple times and replace these multiple lines with one line. This command is designed to work on sorted files.
$ uniq [option] [input-file] [output-file]
$ cat sample
$ uniq sample
$ sort sample -> sample1 $ uniq sample1
$ uniq -c sample1
1 And some are different. 4 It contains some repeated lines. 1 This is a test file for the uniq command.
$ uniq -d sample1
It contains some repeated lines.
$ uniq -u sample1 out $ cat out
And some are different. This is a test file for the uniq command.