Oneliner problem with < and > in variable

A

Ansim

Hello,

I have this oneliner
$_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
@content/;print}else{print}' SMOinfo.xml

where $_start is <Action name="abc" id="_XX_"> , a xml pragma, and
$_new_start is <!-- <Action.....>, same xml pragma but with comment
marks first.

When this oneliner is executet i receives this error:
"Unterminated <> operator at -e line 1.

I've tried several settings in the @content='$_new_start' statement,
everyone failing with different error codes.
Tried to change the ' to ` or " or "' or ´ and without.


The idea is to, in a script, auto magically comment out Action
settings in the xml file, if they are commented in another file.

The one liner is executet once more and end the comment with

$_PERL -ni -we 'BEGIN{@content='$_new_end'} if(/'$_end'/){s//
@content/;print}else{print}' SMOinfo.xml
where $_end="</Action name="abc" id="_XX_">", $_new_end="</Action
id="_XX_"> -->"

Any suggestions on how to solve this?

BR
//Anders
 
P

Peter Makholm

Ansim said:
I have this oneliner
$_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
@content/;print}else{print}' SMOinfo.xml

where $_start is <Action name="abc" id="_XX_"> , a xml pragma, and
$_new_start is <!-- <Action.....>, same xml pragma but with comment
marks first.

Could you try to cut'n'paste exactly what you're writing in you
oneliner. In the above $_new_start isn't anything but undef.

//Makholm
 
M

Michele Dondi

I have this oneliner
$_PERL -ni -we 'BEGIN{@content=3D'$_new_start'} if(/'$_start'/){s//
@content/;print}else{print}' SMOinfo.xml

Quote the inner single quotes. BTW: a shell problem, not a Perl one...


Michele
 
A

Ansim

If i set @content='"$_new_start"' and if(/<Activity.*_MM_FRP_FILE"\>/)

_new_start="<!-- <Activity Name="Firmware Upgrade"
Build_id="_MM_FRP_FILE">" by some grep, nawk.

(Of course not the first and last ".)

i get following output:

Unterminated <> operator at -e line 1.

and nothing is done in the SMOinfo.xml

But, if i set @content='"$_start"' where _start="<Activity
Name="Firmware Upgrade" Build_id="_MM_FRP_FILE">"
then the line in SMOinfo.xml is changed to
Activity Name="Firmware Upgrade" Build_id="_MM_FRP_FILE" , note! the
< > is removed. Not what i wanted.

The oneliner is executed inside a ksh script.

//Anders
 
M

Michele Dondi

If i set @content='"$_new_start"' and if(/<Activity.*_MM_FRP_FILE"\>/)

_new_start="<!-- <Activity Name="Firmware Upgrade"
Build_id="_MM_FRP_FILE">" by some grep, nawk.

(Of course not the first and last ".)

i get following output:

Unterminated <> operator at -e line 1.

and nothing is done in the SMOinfo.xml

But, if i set @content='"$_start"' where _start="<Activity
Name="Firmware Upgrade" Build_id="_MM_FRP_FILE">"
then the line in SMOinfo.xml is changed to
Activity Name="Firmware Upgrade" Build_id="_MM_FRP_FILE" , note! the
< > is removed. Not what i wanted.

The oneliner is executed inside a ksh script.

I think all shells behave more or less the same wrt basic quoting. Can
you post the complete oneliners in their variations and explain how
they fail to work please?

From the first post I gathered that you had a quoting problem of
single quotes inside single quotes. You overcome it like so:

'something \'strange\' indeed'

Here you brought up double quotes. I could not follow your words in
detail admittedly *also* because I'm in a hurry. But remember that
double quotes *interpolate* in Perl, and this may matter.


Michele
 
J

John W. Krahn

Ansim said:
I have this oneliner
$_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
@content/;print}else{print}' SMOinfo.xml

where $_start is <Action name="abc" id="_XX_"> , a xml pragma, and
$_new_start is <!-- <Action.....>, same xml pragma but with comment
marks first.

When this oneliner is executet i receives this error:
"Unterminated <> operator at -e line 1.

I've tried several settings in the @content='$_new_start' statement,
everyone failing with different error codes.
Tried to change the ' to ` or " or "' or ´ and without.


The idea is to, in a script, auto magically comment out Action
settings in the xml file, if they are commented in another file.

The one liner is executet once more and end the comment with

$_PERL -ni -we 'BEGIN{@content='$_new_end'} if(/'$_end'/){s//
@content/;print}else{print}' SMOinfo.xml
where $_end="</Action name="abc" id="_XX_">", $_new_end="</Action
id="_XX_"> -->"

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
 
A

Ansim

Thanks all for the help.

Glenn and Michal helped a lot.

The rest helped me with understanding the importance of qouting.
Perl interpreted the < and > in a strange way othervise.

BR
//Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top