Oneliner problem with < and > in variable
am 14.09.2007 10:41:19 von Ansim
Hello,
I have this oneliner
$_PERL -ni -we 'BEGIN{@content=3D'$_new_start'} if(/'$_start'/){s//
@content/;print}else{print}' SMOinfo.xml
where $_start is , a xml pragma, and
$_new_start is "
Any suggestions on how to solve this?
BR
//Anders
Re: Oneliner problem with < and > in variable
am 14.09.2007 10:54:44 von Peter Makholm
Ansim writes:
> I have this oneliner
> $_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
> @content/;print}else{print}' SMOinfo.xml
>
> where $_start is , a xml pragma, and
> $_new_start is "
>
> Any suggestions on how to solve this?
In perl one-liners:
-n ' if ( // ) { s///; print } else { print } '
Is usually written as:
-p ' s/// '
So:
$_PERL -ni -we 'BEGIN{@content='$_new_start'}
if(/'$_start'/){s//@content/;print}else{print}' SMOinfo.xml
*Should* be written as:
$_PERL -pi -we 'BEGIN{$content='$_new_start'} s/'$_start'/$content/' SMOinfo.xml
Or perhaps just:
$_PERL -pi -we 's/'$_start'/'$_new_start'/' SMOinfo.xml
If that doesn't work then you could try something like this:
$_PERL -spi -we 's/$x/$y/o' -- -x="$_start" -y="$_new_start" SMOinfo.xml
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Re: Oneliner problem with < and > in variable
am 15.09.2007 11:22:00 von Michal Nazarewicz
Ansim writes:
> Hello,
>
> I have this oneliner
> $_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
> @content/;print}else{print}' SMOinfo.xml
How about:
$_PERL -pi -we 'BEGIN{$from = shift @ARGV; $to = shift @ARGV; }
s/$from/$to/o;' "$_start" "$_new_start" SMOinfo.xml
--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-------ooO--(_)--Ooo--