Linux.com

shorter versions

Posted by: Anonymous Coward on February 01, 2006 02:11 AM
Slightly more concise if you specify the field separator as a command switch instead of with a BEGIN rule.

ifconfig | awk -F'[<nobr> <wbr></nobr>:]+' '{if ($3=="addr"){printf "%s:\t%s\n",Sv,$4}else{Sv=$1}}'

instead of

ifconfig | awk 'BEGIN{FS="[<nobr> <wbr></nobr>:]+"};{if ($3=="addr"){printf "%s:\t%s\n",Sv,$4}else{Sv=$1}}'

You could also lose the if, by using a next:

ifconfig | awk -F'[<nobr> <wbr></nobr>:]+' '/inet/{printf "%s:\t%s\n",Sv,$4;next};{Sv=$1}'

If you crunch it down any further than that you'll just end up with something unreadable to all but the illuminati. Like the average perl program!<nobr> <wbr></nobr>;)

#

Return to CLI Magic: Learn to talk awk