Linux.com

CLI Magic: For geek cred, try these one-liners

Posted by: Anonymous [ip: 199.227.154.26] on July 23, 2008 10:48 PM
Sometimes you need uniqueness but also want to preserve order so sorting is out.
In those cases you can use awk.

Arrays in awk can be indexed by strings. $0 is the entire line and $1, $2, etc. are fields within the line.
So...
awk '/@/ && !un[$3]++ {print $3}' incoming_email

The ++ increments the element addressed by $3 and only elements numbered zero, the first, are
printed. Of course you can print other fields or combinations of fields as well.

#

Return to CLI Magic: For geek cred, try these one-liners