[prev] [index] [next]

uniq: remove or count duplicates

The uniq command by default removes all but one copy of adjacent identical lines.

Some options:

-c also print number of times each line is duplicated
-d only print (one copy of) duplicated lines
-u only print lines that occur uniquely (once only)

Surprisingly useful tool for summarising data, typically after extraction by cut. Always preceded by sort (why?).

# extract first field, sort, and tally
cut -f1 data  |  sort  |  uniq -c