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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using perl -pi -e in shell script

Status
Not open for further replies.

hlyeoh

MIS
May 31, 2004
22
MY
Hi,

Is there anyway to use variable in the following case?
The file is not able to update.

perl -pi -e 's/${seq_detail}/${new_seq}/g' ${SEQ_FILE}

alternatif, i try to use sed, but still the file is not updated.

sed -n -e 's/${seq_detail}/${new_seq}/g' ${SEQ_FILE}

Can anyone help to correct my statement above?
Thanks.
 
hi,

do you mean like this?
perl -pi -e 's./${seq_detail}/${new_seq}/g' ${SEQ_FILE}
 
No, I mean like this:

[tt]perl -pi -e "s/${seq_detail}/${new_seq}/g" ${SEQ_FILE}[/tt]

Annihilannic.
 
it works fine. Now it is updated, but it duplicate the result.

original :

Avnet FFS|00000000001
Avnet SCS|00000000001

After execute:
::::::::::::::
ref_id.dat
::::::::::::::
Avnet FFS|00000000002|Avnet FFS|00000000002
Avnet SCS|00000000001

 
Can you post all of your code please, including where it sets the seq_detail and new_seq variables?

Annihilannic.
 
Thanks Annihilannic, the problem solved. It is due to the pipe.

new_seq=${seq_code}"\\|"${t_seq_number_new}
perl -pi -e "s/${old_seq}/${new_seq}/g" ${SEQ_FILE}
 
I was actually thinking why i can't get the same result using sed? Can sed use to substitute?
sed -i 's/${old_seq}/${new_seq}/g' ${SEQ_FILE} to replaces this statement
perl -pi -e "s/${old_seq}/${new_seq}/g" ${SEQ_FILE}
 
Yes, but you will also need to use " quotes with sed. Otherwise the shell will not replace the ${variable} names with the variable contents.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top