uniq—reports on duplicate lines in a file

uniq [ [ –u ] [ –d ] [ –c ] [ +n ] [ –n ] ] [ input [ output ] ]

uniq reads the input file, comparing adjacent lines. In the normal case, the second and succeeding copies of repeated lines are removed; the remainder is written on the output file. Input and output should always be different.

Example A.69.
1  uniq file1 file2
2  uniq -d -2 file3
				

Explanation

  1. Removes duplicate adjacent lines from file1 and puts output in file2.

  2. Displays the duplicate lines where the duplicate starts at third field.

Get Linux Shells by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.