Link to home
Start Free TrialLog in
Avatar of tkir
tkir

asked on

Perl - Replacing a record at a specific position

Hi,

Using Perl, how could you replace a record at a specific position of a fixed length file?    Also, need to do multiple replacement at different positions for the same record.

For example, the file contains the following record:

-->  Need to change THIS first then THIS second ...<rest of line, 700 chars total>

Note:  1st "THIS" is at positions 16-19 and 2nd "THIS" is at position 32-35.

Goal:

Replace position 16 to 19 (len = 4), "THIS", with "XXXX"
and
Replace position 32 to 35 (len = 4), "THIS", with "YYY" << len different

Results:

--> Need to change XXXX first then YYYS second ...<rest of line, 700 chars total>

Note:  The 2nd replacement replaced "THIS" with "YYYS"; 'S' was kept and the records length was not changed, contained 700 chars (same as original)

Thank you



 
I need to change several
I need to modify a fixed length file, at several positions o
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tkir
tkir

ASKER

Thank you!!