LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 09-09-2003, 12:12 PM   #1
ramesh_ps1
LQ Newbie
 
Registered: Sep 2003
Location: Bangalore
Distribution: RH 8.0
Posts: 4

Rep: Reputation: 0
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
 
Old 09-09-2003, 12:45 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
You will need to escape the slashes:
perl -i -p -e "s/######/abcd####\/####\/#####\/#####/g"
 
Old 09-09-2003, 02:40 PM   #3
ramesh_ps1
LQ Newbie
 
Registered: Sep 2003
Location: Bangalore
Distribution: RH 8.0
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 09-09-2003, 08:07 PM   #4
ralpha6
Member
 
Registered: Aug 2002
Posts: 40

Rep: Reputation: 15
I'm no expert, but it looks like you're missing a ";" after "...common\n<\/VirtualHost>"
 
Old 09-10-2003, 01:04 AM   #5
ramesh_ps1
LQ Newbie
 
Registered: Sep 2003
Location: Bangalore
Distribution: RH 8.0
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using sed to replace string in file umk Debian 12 02-01-2012 08:39 AM
sed command to replace slash with backslash stelmed Slackware 13 08-19-2010 05:01 AM
Perl Regexp search-n-replace jpbarto Programming 2 06-16-2005 12:45 PM
How to "Search & Replace" in html files using Perl? rebel Red Hat 8 04-09-2005 12:58 PM
Perl : Troubles to replace a string. philipina Programming 4 07-26-2004 05:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration