Sed sees ip-adres as regular expression.

Hi,

I have a question concerning sed and regular expressions for tru64 unix.

I have a script that will change the ip address in a number of configuration files.  In the script, I use sed to change the ip-adresses.

for x in $config_files ;do
        cp -pr $x $x.temp
        cat $x.temp |sed "s|$old_ip|$new_ip|">$x
done

For most ip adresses, this worked just fine.  Now I need to change 10.255.2.5 into 10.255.2.195, which is giving problems.  Apparently, sed sees the . in the ip-adres as a part of a regular expression and is replacing all ip adresses that match this regular expression.

Is there any way to avoid that sed sees this as a regular expression ?  If not, how can I create a new variable $esc_old_ip that has the esc character before the dot ?

I tried already

esc_old_ip=`echo $old_ip | awk -F "." '{printf $1}';printf "\\\.";echo $old_ip | awk -F "." '{printf $2}';printf "\\\.";echo $old_ip | awk -F "." '{printf $3}';printf "\\\.";echo $old_ip | awk -F "." '{print $4}'`

This line give 10\255\2\5 iso the wanted 10\.255\.2\.5

Hope that anybody can help me urgently.

Kind regards,
Carembeu
CarembeuAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
sorry
perl -i -pe 's|\Q$old_ip\E|$new_ip|g' $config_files
0
 
ozoCommented:
perl -i -e 's|\Q$old_ip\E|$new_ip|g' $config_files


0
 
ozoCommented:
or
esc_old_ip=`echo $old_ip | sed "s|\.|\\\\\\.|g"`
0
All Courses

From novice to tech pro — start learning today.