1. That each record was delimited by #\d+, eg #1008
2. That the delimiter was preceded by Value and Tester
So that following might not be quite what you need but it will give you a start.
#!/usr/bin/perl -w use strict; my $rec_index; my @rec_refs; my @record; my $max = 0; my $count = 0; while (<DATA>) { $count++; push @record, $_; if (/#\d+/) { # Match the end of record push @rec_refs, [@record]; # Store the current record @record = (); $max = $count if $count > $max; # Track max fields in a rec +ord $count = 0; } } # Iterate through the stored records and add the extra fields foreach my $aref (@rec_refs) { $count = 0; foreach my $line (@$aref) { # Add extra fields before the "Tester" field print ",\n" x ($max - $count -3) if $line eq "Tester,\n"; print $line; $count++; } } __DATA__ Ent, Name, SC011, BUN, Tester, Value, #1008 Ent, Name, FS0022L, FUN, TL0324, PLEASE, Tester, Value, #1002 Ent, Name, SC004, TAKE, K530, RUN, K530, RUN, Tester, Value, #1001
--
John.
In reply to Re: Equal line spacing in records of a file
by jmcnamara
in thread Equal line spacing in records of a file
by vanuatu10
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |