uniq

display unique lines of sorted file

Command


SYNOPSIS

uniq [-c|-d|-u] [-f number1] [-s number2] [input_file [output_file]]

uniq [-c|-d|-u] [-number] [+number] [input_file [output_file]]


DESCRIPTION

uniq manipulates lines which occur more than once in a file. The file must be sorted, since uniq only compares adjacent lines. When you invoke this command with no options, it writes only one copy of each line in input_file to output_file. If you do not specify input_file or you specify -, uniq reads the standard input. If you do not specify output_file, uniq uses the standard output.

Options

-c

precedes each output line with the number of times that line occurred in the input.

-d

displays only lines which are repeated (one copy of each line).

-f number1

ignores the first number1 fields when comparing lines. Blanks separate fields in the input.

-s number2

ignores the first number2 characters when comparing lines. If you specify both -s and -f, uniq ignores the first number2 characters after the first number1 fields.

-u

displays only those lines which are not repeated.

You may choose only one of the -c, -d, or -u options.
-number

is an obsolete equivalent to -f number.

+number

is an obsolete equivalent to -s number.


EXAMPLES

uniq
is a filter which prints one copy of each different line in its sorted input.
uniq -f 2 -s 1
compares lines starting with the 2nd character of the 3rd field.
uniq -d
outputs one instance of each repeated line in the input (and omits all unique lines).


DIAGNOSTICS

Possible exit status values are:
0

Successful completion.

1

Failure due to any of the following:

— invalid command line option
— missing number after -f
— missing or invalid number after -s
— inability to open the input or output file
Missing character skip count

You specified -s but did not supply a number after the -s.

Missing number of fields to skip

You specified -f but did not supply a number after the -f.

field skip not a number in "string"

In a -number or +number construct, number wasn't valid. This could arise from a typo when entering a - option.


PORTABILITY

POSIX.2. x/OPEN Portability Guide 4.0.


SEE ALSO

Commands:
comm, sort


Updated MKS Toolkit [3khat16.ico]HP3000 [3khat16.ico]3kMail [archive16.gif]