Using shell script to parse all ip:port values from a line -
i need parse ip:port values in line single line string shown below using shell script. tried lot using awk, cut, sed... not successful. please me. (long) line stored in variable, not in file.
14/03/25 11:53:50 info conf.configuration: dfsdb.properties not found 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.6.133:54310 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.9.65:54310 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.9.66:54310 update: think got better code...
echo "<string>"| grep -oe "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{4,5}"
there might not straight , easy ans because of requirements, can work you,
var="14/03/25 11:53:50 info conf.configuration: dfsdb.properties not found 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.6.133:54310 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.9.65:54310 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.9.66:54310" for separating output,
echo $var | cut -d ">" -f2,3,4,5 --- assuming have 5 values. if more apply loop or try split command take array , iterate on
output : 172.20.6.133:54310 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.9.65:54310 14/03/25 11:53:50 info util.dfsdbutil: namenodeip--->172.20.9.66:54310 ip:port pair
echo $var | cut -d ">" -f2 |cut -d " " -f1 output
172.20.6.133:54310 for each field apply loop , desired ip:port , if possible simplify trouble customize input string can split , feed cut command.
Comments
Post a Comment