I'm trying to learn as much as possible about Linux, I'm currently stuck at trying to grab specific parts of my ifconfig text display so it looks exactly like this:
eth0:
inet 192.168.1.000 netmask 255.255.255.0 broadcast 192.168.1.255
wlan0:
inet 192.168.1.xxx netmask 255.255.255.0 broadcast 192.168.1.255
I've come so close, so far i have tried about a million possible combinations but I'm close to exhausted, this is some of what i have tried.
ifconfig | head -19 | sed 'wlan0|\eth0' | awk '{print $2}'
ifconfig | head -19 | egrep 'wlan0|\eth0' | awk '{print $1}' | sed '/^net/p'
ifconfig | head -19 | egrep 'wlan0|\eth0|' | awk '{print $1}'
ifconfig | cut -d: -f1 | awk '{print $2}' | cut -d: -f1
This is as close as i have come
ifconfig | head -n 2 | cut -d: -f1; ifconfig | tail -8 | head -1
eth0
inet 192.168.1.000 netmask 255.255.255.0 broadcast 192.168.1.255
inet 192.168.1.xxx netmask 255.255.255.0 broadcast 192.168.1.255
I'm missing wlan0 in between 000 and xxx, Thank you for your time and effort.
My Display
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.000 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 xxxxxxxxxxxxxxxxxxxxxxx prefixlen 64 scopeid 0x20<link>
ether xxxxxxxxxxx txqueuelen 1000 (Ethernet)
RX packets 711634 bytes 635444016 (606.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 523020 bytes 98052518 (93.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 4266 bytes 735580 (718.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4266 bytes 735580 (718.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.xxx netmask 255.255.255.0 broadcast 192.168.1.255
inet6 xxxxxxxxxxxxxxxx prefixlen 64 scopeid 0x20<link>
ether xxxxxxxxxxx txqueuelen 1000 (Ethernet)
RX packets 2429 bytes 371836 (363.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 227 bytes 79847 (77.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I just found a way with
ifconfig | head -n 2 | cut -d: -f1; ifconfig | tail -9 | cut -d: -f1 | head -2
But I'm open to more ways if you have them