From the document said that the option --count going to

prefix lines by the number of occurrences

but after I do some test it seems doesn't work.

$ echo -e "a\na\b\nc" |uniq --count
      1 a
      1 a
      1 c

Should the line 'a' occurs 2 times?

1 Answer 1


If I understand what you are trying to do, there is a typo in your original string that is confusing uniq (it thinks there are 1+1+1 lines instead of 2+1+1). There is an "n" missing.

echo -e "a\na\nb\nc" |uniq --count
  2 a
  1 b
  1 c

I guess this is the result you were expecting, as it is coherent with the man page.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.