Re: special character string substitution
- From: nobull67@xxxxxxxxx (Nobull67@xxxxxxxxx)
- Date: Wed, 07 Nov 2007 18:22:16 -0000
On Nov 7, 5:43 pm, cfarine...@xxxxxxxxxxxxxxxxxxxxxxxx (Charlie
Farinella) wrote:
Hi,
I'm trying to substitute a string with a Mason variable in a bunch of
files and not having any luck. For instance I want to change the
string 'testtext' to '<% $bURL %>' in a file:
perl -w -i -p -e "s/testtext/'<% \$bURL %>'/g" test.html
..substitutes '<% %>'
I've tried quotes, double quotes, escape characters in various
configurations, with no luck.
perl -e "print '<% \$bURL %>'"
prints what I expect, so I'm lost as to what I need to write for the
substitution.
Your problem here could well be that your command line shell is
consuming the \ before the $ so there's no \ in the Perl program you
are executing
(What command shell are you using?)
The RHS of s/// is a double-quotish string context you Perl thinks you
are trying to interpolate the perl variable $bURL. You need to protect
the $ twice. There are numerous ways to do this.
Assuming a Bourne-like shell any of the following should work
perl -w -i -p -e "s/testtext/<% \\$bURL %>/g" test.html
perl -w -i -p -e "s/testtext/'<% \$bURL %>'/eg" test.html
perl -w -i -p -e 's/testtext/<% \$bURL %>/g' test.html
perl -w -i -p -e "s'testtext'<% \$bURL %>'g" test.html
.
- Follow-Ups:
- Re: special character string substitution
- From: Charlie Farinella
- Re: special character string substitution
- References:
- special character string substitution
- From: Charlie Farinella
- special character string substitution
- Prev by Date: Re: special character string substitution
- Next by Date: Re: Issue while calling the subroutine dynamically
- Previous by thread: Re: special character string substitution
- Next by thread: Re: special character string substitution
- Index(es):
Relevant Pages
|