In the absence of further information I had to make some assumptions:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.