-------------------------------------------------------------------------------- uniq: print unique records in a file & histogram of records -------------------------------------------------------------------------------- $ uniq -u -d -c sorted_file uniq ONLY works on sorted files. It identifies lines which are unique, equally duplicated lines and make a histogram! -c .. produce a histogram -d .. print only duplicated lines -f n .. ignore the first fields -s n .. ignore the first n characters -u .. print only lines that are not repeated in the input -i .. case insensitive Less useful options -f NFIELDS (avoid comparing the first NFIELDS fields) -i ignore case -s NCHARS (avoid comparing the first NCHARS characters) -w NCHARS (compare no more than NCHARS in lines) $ cat a 6 4 2 6 2 4 2 1 $ sort -n a | uniq #print each distinct member 1 2 4 6 $ sort -n a | uniq -u #print lines which are not duplicated 1 $ sort a | uniq -d #print only lines which are repeated 2 4 6 $ sort a | uniq -c #histogram 1 1 3 2 2 4 2 6 ^ #