I'm wondering if someone can suggest a better way to do it, out of curiosity. If no one has a better way, then here's my way, you're welcome to use it :)
Simple "uniq" (print unique lines):
(Note that I'm not using strict, not using -w. These are meant to be one-liners)perl -ne'print unless $seen{$_}++' filesToUniq
Print out all the seen values for a field (in this example, all the HTTP protocol versions used to access my web server)
That version prints out the first line on which a given protocol is encountered. If you prefer just enumerating the protocols, use:perl -ne'm[HTTP/([^"]+)] or next; print unless $seen{$1}++' access_log
This is hardly "perl rocket science", obviously. But I figured it might be useful, since I wind up typing "$seen{$_}++" a lot every day...perl -ne'm[HTTP/([^"]+)] or next; print "$1\n" unless $seen{$1}++' acc +ess_log
Hmmm, maybe I should drop the 'een' and improve my golf score. Oops, wrong thread! :)
--
Mike
In reply to Better "uniq" idiom? by RMGir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |