This is, in concept fairly straightforward. The details depend on information about the file format which you've not provided.
open the master file.
open a temp file.
read a record, skipping header records, until a significant record or
+end of file.
Split the significant record (see the split function) into fields. Th
+row out all but the last three fields and the key column.
loop through the pointers to the child files
open each child file
read the child file, checking for the key value.
write the appropriate data to a temp file.
close the child file.
repeat until all records in master file have been processed.
close the master file.
close the temp file
open it for appending
open the temp file for reading
read through the temp file, copying records to the end of the master f
+ile.
The key functions to look at are open, split, and grep. Check out Perl's array operators. It probably would be best to use Tie::File, which eliminates the need for opening and closing the master file and keeping a temp file.
In Perl, using negative array indices will count from the end; $array[-1] points to the last element in an array; $array[-2] points to the second to last, etc (symmetry would be nice, but Perl counts array elements from 0, and most computers can't distinguish 0 from -0. Alas.).
emc
Insisting on perfect safety is for people who don't have the balls to live in the real world.
—Mary Shafer, NASA Dryden Flight Research Center
|