1753893 Members
7558 Online
108809 Solutions
New Discussion юеВ

Perl Help

 
SOLVED
Go to solution
Pando
Regular Advisor

Perl Help

Dear Gurus,

I am creating a script for data manipulation..
Below is the sample line.
...
...
export difflotid=$(grep "" $EFILE | awk -F \" '{print $2}')

This would get the value and store it to difflotid variable.

I will be using this variable to be transfer/use in other file.

Perl is suitable for in-line editing for me.

I need to know the syntax (Perl) to replace the the following line below using the difflotid variable from another file.

...
...
Diffusion Lot ID, 11111-11
...
...

Maximum points for all correct replies.

3 REPLIES 3
Muthukumar_5
Honored Contributor
Solution

Re: Perl Help

You can do this with a single script as,

#!/bin/ksh

export difflotid=$(grep "" $EFILE | awk -F \" '{print $2}')

..

# It will automatically update in filename with changes
perl -pi -e "s/^Diffusion LotID.*/$difflotid/"
..

HTH.
Easy to suggest when don't know about the problem!
Tim D Fulford
Honored Contributor

Re: Perl Help

The above works... but I'd use

perl -i.org -pe "s/Diffusion Lot ID.*/$difflotid/"

This will save as .org & will have the edits in it

Regards

Tim
-
Muthukumar_5
Honored Contributor

Re: Perl Help

You can also use sed instead of perl for this as,

sed "s/^Diffusion LotID.*/\$difflotid/" >

IF you want to update into the same file then,

sed -i "s/^Diffusion LotID.*/\$difflotid/"

hth.
Easy to suggest when don't know about the problem!