hi,
I have a local.conf file which has the first line
TOPDIR = "/home/mvdev/workspace/boxer". I want to replace the value to
"/home/common/workspace/mirror". I tried the following perl command that is
perl -p -i -e 's/Path/path1/g' myfile.txt
then
sed '/home/mvdev/workspace/boxer/c \> /home/common/workspace/mirror' local.conf
It did not work. Can you help.
Thnx
amvarma
RudiC
December 13, 2012, 4:36am
2
sed '1 s:/home/mvdev/workspace/boxer:/home/common/workspace/mirror:' local.conf
Thanks Rudic,
when I ran the command, it displayed that it changed, but when I open it separately I dont see the value updated.
You need to send the result to some other file like
sed '1 s:/home/mvdev/workspace/boxer:/home/common/workspace/mirror:' local.conf > local1.conf
and then move it back to local.conf
mv local1.conf local.conf
RudiC
December 13, 2012, 5:03am
5
Yes, as Vikram says, redirect the output to a file and then rename, unless your sed
has the -i
option (edit in place). BUT - I'd rather be careful editing system files in place. Better check result in time.
if we use -i option, will it avoid the rename opion
Hi
Use your perl command like this:
$ p1="/home/mvdev/workspace/boxer"
$ p2="p2="/home/common/workspace/mirror"
$ perl -i -pne "s|$p1|$p2|;" file
Guru.
Yes if you use
sed -i command
then no need to move the file.