On occasion I get output from a command that includes "key value" pairs, with possibly more than one pair per line. As a repeatable example, consider the command
ip addr show dev eth0:
ip addr show dev eth0 | grep -v link/ether 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe0f:dbb3/64 scope link valid_lft forever preferred_lft forever
For the purposes of this example I might want to capture the values following
10.0.2.255 respectively, here). It can be assumed that each keyword will not occur more than once in the input.
The only way I can see to handle this would be capture the output of the source command to a temporary variable, and repeatedly parse that until all the keywords have been processed.
Is there an easier or better way to pick out these "key value" pairs, discarding the remainder of the text?
Suggested example provision and unordered output:
ip addr show dev eth0 | someCommand brd inet mtu mtu 1500 inet 10.0.2.15/24 brd 10.0.2.255