Name
uniq
Synopsis
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.
Common Options
-c
,--count
Print each line once, counting instances of each.
-d
,--repeated
Print duplicate lines once, but no unique lines.
-f
n
,--skip-fields=
n
Ignore first n fields of a line. Fields are separated by spaces or by tabs.
-s
n
,--skip-chars=
n
Ignore first n characters of a field.
-u
,--unique
Print only unique lines (no copy of duplicate entries is kept).
-
-
n
Like
-f
. This original, pre-POSIX syntax is deprecated; use-f
instead.- +
n
Like
-s
. This original, pre-POSIX syntax is deprecated; use-s
instead.
GNU/Linux Options
-D
,--all-repeated
[=
method
]Print all duplicate lines.
-D
takes no delimiter method. The delimiter method method describes how uniq should delimit groups of repeated lines in the output. It takes one of the valuesnone
(default),prepend
(output a newline before each group), orseparate
(output a newline after each group).-i
,--ignore-case
Ignore case differences when checking for duplicates.
-w
n
,--check-chars=
n
Compare only first n characters per line (beginning after skipped fields and characters).
Examples
Send one copy of each line from list to output file list.new (list must be sorted):
uniq list list.new
Show which names appear more than once:
sort names | uniq -d
Show which lines appear exactly three times:
sort names | ...
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.