ifconfig gives following output:
eth0 Link encap:Ethernet HWaddr 4c:87:0e:z3:e7:11
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:35767 errors:0 dropped:0 overruns:0 frame:0
TX packets:35767 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5053027 (5.0 MB) TX bytes:5053027 (5.0 MB)
vmnet1 Link encap:Ethernet HWaddr 60:80:66:m0:00:01
inet addr:192.168.139.1 Bcast:192.168.139.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fec0:1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:70 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
I presently need output like
eth0
wlan0 127.0.0.1
vmnet1 192.168.139.1
so i run command
ifconfig | awk '/encap|inet addr/{ print }'
but i am stuck now, as i need to combine 2 lines based on weather the next line contains the ipaddress pattern. Though shell script may do the trick , But i need a simple single command solution. Though for loops are there in awk , but forward looking into next line , matching & then printing on console is challenge for me .
or is there a simple command / flag for achieving such purpose ?
route command seems to do the trick (awk field extraction!!) , but it doesnot list the inactive interfaces.
ifconfig
output in the question does look a whole lot like Linux ;) – Celada Feb 09 '15 at 09:29sed
one-liner but I'm not familiar enough with buffer handling withsed
. This said, I doubt a script without escape chars is possible. Strange that the second sample doesn't work though because I tested it on Linux Mint and it worked as expected. – Feb 09 '15 at 11:32ip addr show eth0
will show all show also eth0:1, which the script does not expect – Marki555 Jun 07 '16 at 14:31