uniq(1) — Commands
OSF
NAME
uniq − Removes or lists repeated lines in a file
SYNOPSIS
uniq [−c | −d | −u] [+number] [−number] [input-file] [output-file]
The uniq command reads standard input by default, or input_file, compares adjacent lines, removes the second and succeeding occurrences of a line, and writes to standard output or the specified file output_file.
FLAGS
-cPrecedes each output line with a count of the number of times each line appears in the file. This flag supersedes -d and -u.
-dDisplays repeated lines only.
-uDisplays unique lines only.
-numberSkips over the first number-1 fields. A field is a string of nonspace, nontab characters separated by tabs or spaces, or both, from adjacent data on the same line.
+number
Skips over the first number-1 characters. Fields specified by number are skipped before characters.
DESCRIPTION
input_file and output_file must be different files.
Repeated lines must be on consecutive lines to be found. You can arrange them with the sort command before processing.
EXAMPLES
To delete repeated lines in the following file called fruit and save it to a file named newfruit, enter:
uniq fruit newfruit
The file fruit contains the following lines:
apples
apples
bananas
cherries
cherries
peaches
pears
The file newfruit contains the following lines:
apples
peaches
pears
bananas
cherries