Considering I got your input data right, give a try to this script:
#!/usr/local/bin/perl use strict; use Data::Dumper; # use this module for debugging only! my @recs = ([]); my ($in_rec, $row_count, $max_rows) = 3x(0); while (<DATA>) { chomp; if (/Ent/.../Tester/) { # Inside a record! # add record line... push @{$recs[$#recs]}, $_; $row_count++; } else { # add empty record (which will store lines # for any new record to come). push @recs, []; $max_rows = $row_count if ($row_count > $max_rows); $row_count = 0; } } # uncomment these lines to debug.. # print Dumper(\@recs); # print "max rows: $max_rows\n"; # cycle through array of records.. for (@recs) { # if record is not empty.. if ($row_count = scalar @$_) { my $i = 0; # print all lines in this record while ($i < $row_count - 1) { print $$_[$i++] ."\n"; } # print extra 'empty' lines to increase record # size to that of the maximum record in the file. print ",\n" while ($row_count++ < $max_rows); # finally, print the closing line ('Tester,') print $$_[$i] ."\n"; } } __DATA__ Ent, Name, SC011, BUN, Tester, Value, #1008 Ent, Name, FS0022L, FUN, TL0324, PLEASE, Tester, Value, #1002 Ent, Name, SC004, TAKE, K530, RUN, Tester, Value, #1001
And the output:
Ent, Name, SC011, BUN, , , Tester, Ent, Name, FS0022L, FUN, TL0324, PLEASE, Tester, Ent, Name, SC004, TAKE, K530, RUN, Tester,
UPDATE: Included a few comments inside the script to explain how it works. I also assume that each 'record' line is on a separate line. At least, that's how I understood the problem before the original post was reformatted properly ;).

_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/;$_=&#91"ps -e -o pid | "," $2 | "," -v "," "&#93;`@$_`?{print" ++ $1"}:{print"- $1"}&&`rm $1`;print"\n";}

In reply to Re: Equal line spacing in records of a file by vladb
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.