Input 1
eno16780032: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.1 netmask 255.255.255.255 broadcast 192.168.0.254
ether 00:50:56:00:00:00 txqueuelen 1000 (Ethernet)
eno33559296: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.2 netmask 255.255.255.255 broadcast 192.168.0.254
ether 00:50:56:00:00:01 txqueuelen 1000 (Ethernet)
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 0 (Local Loopback)
Input 2
bond0 Link encap:Ethernet HWaddr 00:50:56:00:00:00
inet addr:192.168.0.1 Bcast:192.168.0.254 Mask:255.255.254.255
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
bond0:0 Link encap:Ethernet HWaddr 00:50:56:00:00:00
inet addr:192.168.0.1 Bcast:192.168.0.254 Mask:255.255.254.255
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
eth0 Link encap:Ethernet HWaddr 00:50:56:00:00:00
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
eth1 Link encap:Ethernet HWaddr 00:50:56:00:00:00
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
I want output as like, ( Basically to extract Interface, IP and Hardware Address )
Output1
eno16780032 192.168.0.1 00:50:56:00:00:00
eno33559296 192.168.0.2 00:50:56:00:00:01
lo 127.0.0.1
Output2
bond0 192.168.0.1 00:50:56:00:00:00
bond0:0 192.168.0.2 00:50:56:00:00:00
eth0 00:50:56:00:00:00 ===> No IP since its under bonding
eth1 00:50:56:00:00:00 ===> No IP since its under bonding
lo 127.0.0.1
I've tried with awk (awk '/flags|Link/{a=$1;hw=$NF;next;} /inet /{ip=$2;print a,ip,hw}'),
but since Not all match pattern available on each line Unable to get the desired ouput.
So thinking to add matching pattern empty "inet addr:" on input 2 file for the interfaces are part of bonding and the things would be fine.
Can you please help either to add empty "inet addr:" after interface line
eth0 Link encap:Ethernet HWaddr 00:50:56:00:00:00 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 inet addr: <==== Insert empty line
or
- To get the desired output as mentioned above.