Re: special character string substitution



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


.



Relevant Pages

  • Re: Tascam DM-4800 opinions?
    ... Good luck getting $2,000 for a d8b shell. ... $2000 for a d8b with the internal clock card and maybe an MFX ... I can sell it before the DSP board goes again ...
    (rec.audio.pro)
  • Re: snippet of configure script - explain please
    ... that was made to fill in the shell variable... ... $ echo $ ... but is it stated anywhere that this shorthand is legitimate? ... If parameter is set and is non-null, substitute word; ...
    (freebsd-questions)
  • Re: Can I display inline images in a dialog box using "dialog" or a similar CLI tool?
    ... I should just forget trying to do this in the shell altogether. ... (although Firefox with the Vimperator extension comes close). ... solutions that rely upon the luck of an appropriate ... "MozzIE": XForms plugin for FireFox ...
    (comp.unix.shell)
  • Re: tilde expansion not working in makefiles
    ... The tilde's aren't being expanded to the current home directory. ... make won't substitute the tilde in the command but your shell should do. ...
    (comp.unix.programmer)
  • Re: nice job USA
    ... our guys fought hard and never even went into a ... shell until the last few minutes. ... with a little luck we coulda won. ...
    (rec.sport.tennis)