LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (https://www.linuxquestions.org/questions/red-hat-31/)
-   -   problem in perl replace command with slash (/) in search/replace string (https://www.linuxquestions.org/questions/red-hat-31/problem-in-perl-replace-command-with-slash-in-search-replace-string-90912/)

ramesh_ps1 09-09-2003 12:12 PM

problem in perl replace command with slash (/) in search/replace string
 
I want to replace "#######" in a file abcdef.pl with "abcd####/####/#####/#####"

regular perl -i -p -e "s/######/abcd####/####/#####/#####/g",abcdef.pl
doesnot seem to work due to "/" and "#".

Please help me to overcome this problem

or guide me the procedure to do the same with file access and edit method
Thanks in advance for the response
Ramesh

david_ross 09-09-2003 12:45 PM

You will need to escape the slashes:
perl -i -p -e "s/######/abcd####\/####\/#####\/#####/g"

ramesh_ps1 09-09-2003 02:40 PM

I think I had given less information, Please check the complete proble.

consider

/root/abc.pl containing
##########


and I am executing rep.pl containing

$ser="##########";
$domain ="newdomain";
$extension="com";
$x = "<VirtualHost www.$domain.$extension>\n\tServerAdmin admin@$domain.$extension\n\tDocumentRoot \/home1\/$domain\/html\n\tServerName www.$domain.$extension\n\tErrorLog logs\/www.$domain.$extension-error_log\n\tCustomLog logs\/www.$domain.$extension-access_log common\n<\/VirtualHost>"
$result=`perl -i -p -e 's/$ser/$x/g;',/root/abc.pl`;

I am getting a error which says something like this
---------------------------------------------------

"Bareword found where operator expected at -e line ..., near "DocumentRoot"....
(Might be a runaway multi-line // string on line 1)
(Do you need to predeclare DocumentRoot?)

Can any on esove this problem?

Regards,
Ramesh. P. S

ralpha6 09-09-2003 08:07 PM

I'm no expert, but it looks like you're missing a ";" after "...common\n<\/VirtualHost>"

ramesh_ps1 09-10-2003 01:04 AM

replacement probmel in perl
 
Quote:

Originally posted by ralpha6
I'm no expert, but it looks like you're missing a ";" after "...common\n<\/VirtualHost>"
Hello Ralph,
(;) doesnt seem to have any significance near "<\/VirtualHost>",
I tried different combinations but the result remains same.
Can you please check the code again?

Regards,
Ramesh


All times are GMT -5. The time now is 03:03 AM.