The target of the following perl one liner code is to replace the first three octets ( in case the four octet is digit/number - xxx.xxx.xxx.digit )
- remark - I use linux and solaris machines
The problem is that the perl one liner will also replace the first three octets while the four octet IP is not valid IP octet ( for example 5.5.5.555 )
The following perl one liner code example show how the perl syntax replaced the first three octets in spite the four octet isn’t VALID IP
# export OLD_IP=1.1.1
# export NEW_IP=5.5.5
# echo 1.1.1.555 | perl -i -pe 'next if /^ *#/; s/(?<![\d.])\Q$ENV{OLD_IP}\E(?=\.\d)/$ENV{NEW_IP}/g'
5.5.5.555
Please advice what need to add in my perl one liner code , in order to replace the first three octets
only if four octet is VALID IP ( between 0 – 255 )