Edit: Sample output of ifconfig
enp2s0f1: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
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 2540 bytes 207824 (202.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2540 bytes 207824 (202.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.x broadcast xxx.xxx.xxx.xxx
inet6 xxxx::xxxx:xxxx:xxxx:xxxx prefixlen 64 scopeid 0x20<link>
ether xx:xx:xx:xx:xx:xx txqueuelen 1000 (Ethernet)
RX packets 1413004 bytes 634560717 (605.1 MiB)
RX errors 0 dropped 2 overruns 0 frame 0
TX packets 279420 bytes 36406046 (34.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I have this nice written code by other helpful user and I need to modify output of it. I must admit I have a hard time doing it.
ifconfig |
awk '
/^[[:alnum:]]+: / {
n = $1
p = 1
}
n !~ /^lo/ && /^[[:blank:]]+(inet|ether) / {
if (p) {
print n
p = 0
}
print $1, $2
}'
Here's correct output from it:
enp2s0f1:
ether xx:xx:xx:xx:xx:xx
wlp3s0:
inet xxx.xxx.xxx.xxx
ether xx:xx:xx:xx:xx:xx
And this is how I need it to be modifed:
(with created columns inet_name, ip_address, mac_address)
inet_name ip_address mac_address
enp2s0f1: ether xx:xx:xx:xx:xx:xx
wlp3s0: inet xxx.xxx.xxx.xxx ether xx:xx:xx:xx:xx:xx
ifconfig
.