I have a file that contains ifconfig data for all my servers and lists the hostname before the ifconfig.
For example:
==== Host1 ====
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
bge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet xx.xx.xxx.x netmask ffffffc0 broadcast xx.xx.xxx.xx
bge1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet xxx.xx.xxx.xx netmask ffffff00 broadcast xxx.xx.xxx.xxx
bge2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
inet xxx.xx.xx.xx netmask ff000000 broadcast xxx.xxx.xxx.xxx
bge3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 5
inet xx.xx.xxx.xxx netmask ffffffc0 broadcast xx.xx.xxx.xxx
==== Host2 ====
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
bge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet xx.xx.xxx.xx netmask ffffffc0 broadcast xx.xx.xxx.xx
bge1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet xxx.xx.xxx.xx netmask ffffff00 broadcast xxx.xx.xxx.xxx
bge2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
inet xxx.xx.xx.xx netmask ffff0000 broadcast xxx.xx.xxx.xxx
bge3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 5
inet xx.xx.xxx.xxx netmask ffffffe0 broadcast xx.xx.xxx.xxx
What I want is:
Host1
lo0: 127.0.0.1
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
Host2
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
I can cat the file and use:
cat s1 | awk '$1~/:$/{f=$1;getline;print f,$2}'
to display:
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
But I need the hostname to separate the interfaces as I described above.
Thanks!
For example:
==== Host1 ====
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
bge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet xx.xx.xxx.x netmask ffffffc0 broadcast xx.xx.xxx.xx
bge1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet xxx.xx.xxx.xx netmask ffffff00 broadcast xxx.xx.xxx.xxx
bge2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
inet xxx.xx.xx.xx netmask ff000000 broadcast xxx.xxx.xxx.xxx
bge3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 5
inet xx.xx.xxx.xxx netmask ffffffc0 broadcast xx.xx.xxx.xxx
==== Host2 ====
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
bge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet xx.xx.xxx.xx netmask ffffffc0 broadcast xx.xx.xxx.xx
bge1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
inet xxx.xx.xxx.xx netmask ffffff00 broadcast xxx.xx.xxx.xxx
bge2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
inet xxx.xx.xx.xx netmask ffff0000 broadcast xxx.xx.xxx.xxx
bge3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 5
inet xx.xx.xxx.xxx netmask ffffffe0 broadcast xx.xx.xxx.xxx
What I want is:
Host1
lo0: 127.0.0.1
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
Host2
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
I can cat the file and use:
cat s1 | awk '$1~/:$/{f=$1;getline;print f,$2}'
to display:
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
bge0: xx.xx.xxx.xxx
bge1: xx.xx.xxx.xxx
bge2: xx.xx.xxx.xxx
bge3: xx.xx.xxx.xxx
But I need the hostname to separate the interfaces as I described above.
Thanks!