My target is to replace only the three first digits in IP address with new IP address For example
NEW three first three digits – 17.100.10
OLD three first three digits - 12.200.10
Existing IP address in file - 12.200.10.2
Then I will get the new IP as 17.100.10.2
So I write the following Perl command in order to perform the replace action
But the problem is that if the NEW IP matches the three last digits then it will replace them also
So
What need to change in my Perl command in order to replace only the three first digits in IP address?
Real Example1 that described the problem:
export OLD_IP=192.9.1
export NEW_IP=172.192.9
.
echo 1.192.9.1 | perl -i -pe 'next if /^ *#/; s/(\b|\D)$ENV{OLD_IP}(\b|\D)/$1$ENV {NEW_IP}$2/g'
1.172.192.9
.