Thursday, December 15, 2011

Simplest awk program for printing only unique lines? awk '!(saw[$0]++)'

awk '!(saw[$0]++)'

Prints only unique whole lines from stdin, regardless of line order. I now forget where I first saw this (stackoverflow?), but if I put it here I know where to find it again.
I have written some longer and more self-documenting versions, but you have to admire the elegance of this one.

Connie L. O'Dell
Sr. Verification Specialist
CO Consulting - Boulder, CO -

No comments:

Post a Comment