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 cUseful 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 |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access