uniq - Removes or lists repeated lines in a file
uniq [-cdu] [-f fields] [-s chars] [input-file[output-file]]
uniq [-cdu] [-fields] [+chars] [input-file[output-file]]
command reads from the specified
input_file, compares adjacent lines, removes the second and
succeeding occurrences of a line, and writes to standard output.
Interfaces documented on this reference page conform to industry standards as follows:
uniq: XPG4, XPG4-UNIX
Refer to the
reference page for more information
about industry standards and associated tags.
Precedes each output line with a count of the number of times each line appears in the file. This option supersedes the -d and -u options. Displays repeated lines only. Ignores 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:
A pathname for the input file.
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
command before processing.
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
The following exit values are returned:
An error occurred.
The following environment variables affect the execution of
Provides a default value for the internationalization variables
that are unset or null. If
is unset or null, the corresponding value from the default locale is used.
If any of the internationalization variables contain an invalid setting, the
utility behaves as if none of the variables had been defined.
If set to a non-empty string value, overrides the values of
all the other internationalization variables.
Determines the locale for the interpretation of sequences
of bytes of text data as characters (for example, single-byte as opposed to
multibyte characters in arguments).
Determines the locale for the format and contents of diagnostic
messages written to standard error.
Determines the location of message catalogues for the processing
Commands: comm(1), sort(1)