in reply to Converting a fixed-width report to an Excel-friendly format
$LINEFORMAT = "A10 A20 A15 A12"; # adjust to your field widths my @fields; # presuming the input is stdin. otherwise, chop it into lines however +you like while (<>) { my @line = unpack $LINEFORMAT, $_; if ($line[0]) { # new record if ($fields[0]) { # already have a record read in, print + it print join ("|", @fields), "\n"; @fields = (); } @fields = @line; $fields[0] =~ s/^\r//; # strip linefeeds. } else { $fields[$_] .= " $line[$_]" for 0..$#line; } } # print the last record print join ("|", @fields), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting a fixed-width report to an Excel-friendly format
by Anonymous Monk on Oct 25, 2006 at 20:08 UTC |