in reply to Equal line spacing in records of a file

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";}