bash - shell script pattern matching -
need on shell script.
i have following result in file
name-label ( rw) : host1 networks (mro): 1/ip: 192.168.1.2; 0/ip: 192.168.1.10 name-label ( rw) : host2 networks (mro): 1/ip: 192.168.1.15; 1/ipv6/0: fe80::9060:b6ff:fec1:7bbb; 0/ip: 192.168.1.20; 0/ipv6/0: fe80::286d:7cff:fefe:3ed7
i want hostname , corresponding 0/ip value file. final output be
host1 192.168.1.10 host2 192.168.1.20
perl solution:
perl -ne '/^name-label .*: (.+)/ , $name = $1; m(0/ip: ([0-9.]+)) , print "$name $1\n"'
name-label stored in variable, it's printed ip when processing next line.
Comments
Post a Comment