[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sed sees ip-adres as regular expression.

Posted on 2006-06-11
5
Medium Priority
?
413 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:Carembeu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 16882782
perl -i -e 's|\Q$old_ip\E|$new_ip|g' $config_files


0
 
LVL 84

Expert Comment

by:ozo
ID: 16882852
or
esc_old_ip=`echo $old_ip | sed "s|\.|\\\\\\.|g"`
0
 
LVL 84

Accepted Solution

by:
ozo earned 2000 total points
ID: 16882870
sorry
perl -i -pe 's|\Q$old_ip\E|$new_ip|g' $config_files
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question