UNIQ - display unique lines in file.

Syntax:

uniq filename [option]*

Examples:

uniq stuff
uniq /frodo_baggin -u
uniq other +u

Options:

+Unique
displays only the lines in the file that did not have duplicates.
-Unique
displays only the lines in the file that did have duplicates. (In other words, -Unique "subtracts" out the unique lines.)
+Verbose
displays a count in the left margin (7 columns) of the number of times a duplicate line is repeated. UNIQ leaves the margin blank if the line occurs only once.

Description:

UNIQ examines a file for duplicate lines. Duplicate lines are only detected if they are consecutive. For example, consider a file "sample" containing

b
a
a
b
c

The output of

uniq sample

would be

b
a
b
c

The output of UNIQ consists of the lines in the file with duplicate lines removed. As shown above, UNIQ does not consider the "b" lines to be duplicate because they aren't adjacent. The output of

uniq sample +unique

is

b
b
c

because these are the lines that had no duplicates. The output of

uniq sample -unique

is just

a

If you want to remove the duplicate lines from a file, redirect the output of UNIQ to a temporary file, then copy the temporary file back, as in

uniq sample >tmp
copy tmp sample

Commands of the following form do NOT work:

uniq sample >sample

Notes:

UNIQ truncates lines of length longer than 1023 characters.

Copyright © 1996, Thinkage Ltd.