0

I'm facing a difficulty with the unix uniq command. I have a file containing a list of ids that looks like this (output from head -5 list.txt) :

IBNUKWG02JZU4E
IBNUKWG02JZULO
IBNUKWG02JZUMG
IBNUKWG02JZUZS
IBNUKWG02JZV0R

The files contains 619142 lines (cat list.txt | wc -l ), and contains duplicate, for example if I run the command ( -c flag returns the number of occurrence of the line )

cat list.txt | grep IBNUKWG02JZULO | uniq -c 

it returns

  2 IBNUKWG02JZULO

but if I run the command ( -u flag to only print unique lines)

   cat list.txt | uniq -u | wc -l 

it returns 619142, as if duplicated lines weren't detected. How is it possible ?

felix
  • 9,007
  • 7
  • 41
  • 62

1 Answers1

6

before using uniq use sort.

cat list.txt | sort | uniq -u | wc -l 
tso
  • 4,732
  • 2
  • 22
  • 32