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.

Cheers,
Connie L. O'Dell
Sr. Verification Specialist
c.odell@co-consulting.net
303-641-5191
_____________________________________________
CO Consulting - Boulder, CO - http://co-consulting.net

No comments:

Post a Comment