UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: Reference: ungetChapter 2
UNIX Commands
Next: Reference: units
 

uniq

uniq [options] [file1 [file2]]

Remove duplicate adjacent lines from sorted file1, sending one copy of each line to file2 (or to standard output). Often used as a filter. Specify only one of -c, -d, or -u. See also comm and sort.

Options

-c

Print each line once, counting instances of each.

-d

Print duplicate lines once, but no unique lines.

-u

Print only unique lines (no copy of duplicate entries is kept).

-n

Ignore first n fields of a line. Fields are separated by spaces or by tabs.

+n

Ignore first n characters of a field.

Examples

Send one copy of each line from list to output file list.new:

uniq list list.new

Show which names appear more than once:

sort names | uniq -d

Show which lines appear exactly three times:

sort names | uniq -c | grep "3 "


Previous: Reference: ungetUNIX in a Nutshell: System V EditionNext: Reference: units
Reference: ungetBook IndexReference: units

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System