Error: Find the pattern in the file and replace

Hi all,

I have requirement where i need to find a pattern and replace it by new word. I used the below perl command

echo `perl -p -i -e "s/AbCdEf/PqRsTu/g;" FileName.txt`

But I am getting an error as below

Can't do inplace edit Not a Owner

and the file FileName.txt gets deleted from that folder.
Is there any other options (With out using a intermediate file).

Hi Krish,
You can try

sed -i -e's/SEARCH_STRING/REPLCE_STRING/g;' <filename>

if at all you wanna work with sed .I mean other than perl

sed s/"$OSTRING"/"$NSTRING"/g $FILENAME > NEWFILE

Hi Gaurav,

I tried using sed , it gave the follow error

sed: illegal option -- i
Usage: sed [-n] Script [File ...]
sed [-n] [-e Script] ... [-f Script_file] ... [File ...]

Hi Amit,

Thanks for ur reply. The command you have given uses an temp file or intermediate file which i should not use as the file i am going to edit is very huge in MB.

you can redirect the out put to the same file . I am not sure but you can check it with a sample file

sed s/"$OSTRING"/"$NSTRING"/g $FILENAME > $FILENAME

You cannot do like tha. B'coz it will delete all the contents in the file.

print "ars.txt" | sed s/oldstring/newstring/g

here ars.txt is my file name. i have checked in my system and its working

try the following

sed -e's/SEARCH_STRING/REPLCE_STRING/g;' <filename>

also in vi editor you can use the following

:%s/OLDS/NEWS/g