#!/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 () { 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 #### Ent, Name, SC011, BUN, , , Tester, Ent, Name, FS0022L, FUN, TL0324, PLEASE, Tester, Ent, Name, SC004, TAKE, K530, RUN, Tester, #### $"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+)-.*)$/;$_=["ps -e -o pid | "," $2 | "," -v "," "]`@$_`?{print"+ $1"}:{print"- $1"}&&`rm $1`;print"\n";}