Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call "perl -ipe" inside a Korn Shell Script

Status
Not open for further replies.

Ditter

Programmer
Sep 11, 2000
16
0
0
FR
Hi!

I've been trying to use perl -ipe inside a Korn Shell Script top perform substitutions. A sample code is:

...
CRITERIA="'s/$SEARCH_STRING/$REPLACE_STRING/g'"
...
/usr/bin/perl -ipe $CRITERIA $FILE
...

Where:
$SEARCH_STRING is a korn shell var that I've created to
store dynamic search criteria strings.

$REPLACE_STRING is the substitution string.

$FILE is the file where the substitutions will be performed.

===================
PROBLEM:
===================
PERL call is not translating properly shell variables.
I've also tried:

/usr/bin/perl -ipe "$CRITERIA" $FILE
/usr/bin/perl -ipe \$CRITERIA $FILE

And it doesn't work. What's wrong???

 
You may get more accurate replies in the Perl forum

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I presume you realise you will need to set the value of the CRITERIA variable every time the value of SEARCH_STRING or REPLACE_STRING changes?

Try taking out the extra single quotes when you set the value of CRITERIA, e.g.

[tt]CRITERIA="s/$SEARCH_STRING/$REPLACE_STRING/g"[/tt]

Because they are quotes within quotes (or a variable) they will get passed directly in to Perl, which doesn't need them.

Just use this syntax:

[tt]/usr/bin/perl -ipe "$CRITERIA" $FILE[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top