1

If I had a log file looking like this:

A
A
B
C
C
C
A
B
B

I would like to output (remove the immediately-successive duplicates):

A
B
C
A
B

How do I do this?

6

That's the job for uniq:

LC_ALL=C uniq file

GNU uniq in some locales can report first of sequences of lines that sort the same. Using LC_ALL=C forced bytes comparison behavior, give you persistent result.

-1
$ cat /var/log/file | sort | uniq
1
  • 2
    If you were going to do this you could reduce it to a single command sort -u /var/log/file. But no matter how you phrase it, it's still not correctly answering the question. – roaima Jun 13 '15 at 18:45

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.