Learn about Linux
Download Linux
Get Linux help
Get special offers on:
Linux Application Dev Programming Software
Email:
I like this version:
In a shell script I would write it like this:
<nobr> <wbr></nobr><tt>/sbin/ifconfig | awk ' /^[! ]/ {iface=$1} /inet addr/ { split($2,addr,":") print iface" = "addr[2] } '</tt>
As a one-liner it looks like this:
<nobr> <wbr></nobr><tt>/sbin/ifconfig | awk '/^[! ]/{iface=$1}<nobr> <wbr></nobr>/inet addr/{split($2,addr,":");print iface" = "addr[2]}'</tt>
As a previous poster pointed out, don't forget `sed' when doing simple stuff. (Just don't expect to be able to maintain the code if it gets complicated)
#
Return to CLI Magic: Learn to talk awk
© Copyright 1999-2008 - SourceForge, Inc., All Rights Reserved About Linux.com - Privacy Statement - Terms of Use - Advertise - Trademark - Ask Linux Questions - Write for Us - RSS Feed ThinkGeek - Slashdot - SourceForge.net - freshmeat - Surveys - Jobs
Re:Get a list of your interface addresses
Posted by: Anonymous Coward on January 17, 2006 11:11 AMI like this version:
In a shell script I would write it like this:
As a one-liner it looks like this:
As a previous poster pointed out, don't forget `sed' when doing simple stuff. (Just don't expect to be able to maintain the code if it gets complicated)
#