Linux.com

Re:Get a list of your interface addresses

Posted by: Anonymous Coward on January 17, 2006 11:11 AM

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