Name
uniq — stdin stdout - file -- opt --help --version
Synopsis
uniq [options
] [files
]
The uniq
command operates
on consecutive, duplicate lines of text. For example, if you have a
file myfile:
$ cat myfile a b b c b
then uniq
would detect and
process (in whatever way you specify) the two consecutive b’s, but
not the third b.
$ uniq myfile a b c b
uniq
is often used after sorting a
file:
$ sort myfile | uniq a b c
In this case, only a single b remains because all three were
made adjacent by sort
, then
collapsed to one by uniq
. Also,
you can count duplicate lines instead of eliminating them:
$ sort myfile | uniq -c 1 a 3 b 1 c
Useful options
|
Count adjacent duplicate lines. |
|
Case-insensitive operation. |
|
Print unique lines only. |
|
Print duplicate lines only. |
|
Ignore the first
|
|
Ignore the first
|
|
Consider only the
first |
Get Linux Pocket Guide, 2nd 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.