ifconfig |
awk '
FNR>1 && /^[^[:space:]]/ {print ""}
{printf "%s", $0}
END {print ""}
'
how to join ifconfig output to a line per interface
Frage
how do i convert the following output with sed? from:
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
igb0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2
inet 10.1.1.1 netmask ffffff00 broadcast 10.1.1.255
groupname mnic_data
to:
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000
igb0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2 inet 10.1.1.1 netmask ffffff00 broadcast 10.1.1.255 groupname mnic_data
I have tried
sed -n '/^[a-z]/{x;1!s/\n/ /g;1!p;};H'
but no luck! appreciate your help in advance
Lösung 2
Andere Tipps
You can try this:
$ sed -e :a -e '$!N;s/\n / /;ta' -e 'P;D' inputfile
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000
igb0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2 inet 10.1.1.1 netmask ffffff00 broadcast 10.1.1.255 groupname mnic_data
EDIT: To get rid of the extra spaces in the output above, you can use:
$ sed -e :a -e '$!N;s/\n\s\+/ /;ta' -e 'P;D' inputfile
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000
igb0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2 inet 10.1.1.1 netmask ffffff00 broadcast 10.1.1.255 groupname mnic_data
does this help (awk)?
awk '/:/&&f{print ""}{printf "%s", $0;f=1}'
test
kent$ echo "lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
igb0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2
inet 10.1.1.1 netmask ffffff00 broadcast 10.1.1.255
groupname mnic_data"|awk '/:/&&f{print ""}{printf "%s", $0;f=1}'
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000
igb0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2 inet 10.1.1.1 netmask ffffff00 broadcast 10.1.1.255 groupname mnic_data
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow