5

awk to substitute ip without zero left padding

view full story
linux-howto

http://www.unix.com – Hello All, I have this script to awk IP to new file. #awk '/myip|yourip/ {sub(/...\....\....\..../, newip)}1' newip=$IP existing.txt > new.txt When existing.txt has myip=192.168.123.123 and $IP has 192.168.12.12, the awk script is not working. But while I add zero left padding to $IP i.e, 192.168.012.012 it works. Same the case when myip=192.168.12.12 and $IP has 192.168.123.123, does not work. Inshort, the IP format need to be 3 digit decimal to work. Any suggestions. Regards Shaan (HowTos)