Linux.com

Re:Get a list of your interface addresses

Posted by: Anonymous Coward on January 17, 2006 12:01 AM
Well, it's pretty easy in Sed:

ifconfig | sed -n '/HWaddr/{N;s/^\([^ ]*\).*inet addr:\([^ ]*\).*/\1: \2/p}'

Or if you want your loopback too, you can use

ifconfig | sed -n '/Link encap/{N;s/^\([^ ]*\).*inet addr:\([^ ]*\).*/\1: \2/p}'

These can be shortened a bit as "Link encap" can be just "Link" (or even "Li") and you don't really ned the whole "inet addr:" bit, when "addr:" or even "r:" would do.

Making a final sedlet:

ifconfig | sed -n '/HW/{N;s/^\([^ ]*\).*r:\([^ ]*\).*/\1: \2/p}'

or

ifconfig | sed -n '/Li/{N;s/^\([^ ]*\).*r:\([^ ]*\).*/\1: \2/p}'

Hurray for sed!<nobr> <wbr></nobr>:)

-gumnos

#

Return to CLI Magic: Learn to talk awk