uniq(1) — Commands
NAME
uniq − Removes or lists repeated lines in a file
SYNOPSIS
uniq [−cdu] [-f fields] [-s chars] [-fields] [+chars] [input-file [output-file]]
The uniq command reads from standard input (default), or from the specified input_file, compares adjacent lines, removes the second and succeeding occurrences of a line, and writes to standard output or to 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.
-f fieldsIgnores the first fields fields on each input line when doing comparisons, where fields is a positive decimal integer. A field is the maximal string matched by the basic regular expression:
[[:blank:]]∗[^[:blank:]]∗
If the fields argument specifies more fields than appear on an input line, a null string is used for comparisons.
-s charsIgnores the specified number of characters when doing comparisons. The chars argument is a positive decimal integer.
If specified with the -f flag, the first chars characters after the first fields fields are ignored. If the chars argument specifies more characters than remain on an input line, uniq uses a null string for comparison.
-uDisplays unique lines only.
-fieldsEquivalent to -f fields. (Obsolescent)
+charsEquivalent to -s chars. (Obsolescent)
DESCRIPTION
The input_file and output_file arguments must be different files. If the input_file operand is not specified, or if it is -, uniq uses standard input.
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
bananas
cherries
peaches
pears