LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Thread Tools
Old 09-09-2003, 01:12 PM   #1
ramesh_ps1
LQ Newbie
 
Registered: Sep 2003
Location: Bangalore
Distribution: RH 8.0
Posts: 4
Thanked: 0
problem in perl replace command with slash (/) in search/replace string


[Log in to get rid of this advertisement]
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
ramesh_ps1 is offline     Reply With Quote
Old 09-09-2003, 01:45 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,036
Thanked: 0
You will need to escape the slashes:
perl -i -p -e "s/######/abcd####\/####\/#####\/#####/g"
david_ross is offline     Reply With Quote
Old 09-09-2003, 03:40 PM   #3
ramesh_ps1
LQ Newbie
 
Registered: Sep 2003
Location: Bangalore
Distribution: RH 8.0
Posts: 4
Thanked: 0

Original Poster
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
ramesh_ps1 is offline     Reply With Quote
Old 09-09-2003, 09:07 PM   #4
ralpha6
Member
 
Registered: Aug 2002
Posts: 38
Thanked: 0
I'm no expert, but it looks like you're missing a ";" after "...common\n<\/VirtualHost>"
ralpha6 is offline     Reply With Quote
Old 09-10-2003, 02:04 AM   #5
ramesh_ps1
LQ Newbie
 
Registered: Sep 2003
Location: Bangalore
Distribution: RH 8.0
Posts: 4
Thanked: 0

Original Poster
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
ramesh_ps1 is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 9 10-28-2009 05:40 AM
sed command to replace slash with backslash stelmed Slackware 6 05-28-2008 06:26 AM
Perl Regexp search-n-replace jpbarto Programming 2 06-16-2005 01:45 PM
How to "Search & Replace" in html files using Perl? rebel Red Hat 8 04-09-2005 01:58 PM
Perl : Troubles to replace a string. philipina Programming 4 07-26-2004 06:09 AM


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

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration