Going by the spelling error "bananaswiithapples.gif", I assume that you typed the sample in by hand rather than C&Ping from the real data. At least I hope you did because your records are inconsistant.

In the first record, the third field is wrapped at 8 chars. In the second record, the first two lines of that third field are wrapped at 8 chars and the last line at 9. In the third record, the first two lines of the third field are wrapped at 9 and the last line extends to 10.

There are similar inconsistacies in the wrapping of the second field/first record. I've adjusted the data to fit my assumption and I apologies if it is wrong.

This determines the output formatting by finding the maximum width of each field. It assumes that you have enough memory to accumulate all the records in memory. Otherwise it would be necessary to do two passes through the file:

#! perl -slw use strict; ## The A template takes care of trailing spaces my $inTempl = 'A8 x1 A9 x1 A8 A*'; my @headers = split ' ', <DATA>; ## Are these headers used? my( @output, $accum ); while( my $line = <DATA> ) { chomp $line; my @bits = unpack $inTempl, $line; s[^\s*][]g for @bits; ## Trim leading spaces if( $line =~ m[^\S] ) { ## Start of a new record. ## Add to the list push @output, $accum if $accum; ## Start a new accumulation $accum = \@bits; } else { ## Append to the accumulators $accum->[ $_ ] .= $bits[ $_ ] for 0 .. $#bits; } } push @output, $accum; ## Don't forget the last record. ## Determine the output field widths my @w = ( 0 ) x 4; for my $ref ( @output ) { for my $i ( 0 .. 3 ) { my $len = length( $ref->[ $i ]||'' ); $w[ $i ] = $len if $w[ $i ] < $len; } } ## Build an output template with a extra space between fields my $outTempl = join ' ', map 'A' . ($_+1), @w; ## And output print pack $outTempl, @$_ for @output; __DATA__ NodeName FileName PathName BackupDate BD3101 bananaswi \breakfa 2007-03-06 ithapple st\fruit 14:02:31.000000 s.gif s\tree\ TP4223 chocolate \sweet\d 2006-02-28 caramelfu esserts\ 21:16:41.000000 dge.gif hershey\ EO2123 tofuwith \organic 2007-07-16 peas.gif \vegetab 13:55:06.000000 les\legu mes\

Produces

C:\test>632548 BD3101 bananaswiithapples.gif \breakfast\fruits\tree\ 2007-03- +0614:02:31.000000 TP4223 chocolatecaramelfudge.gif \sweet\desserts\hershey\ 2006-02- +2821:16:41.000000 EO2123 tofuwithpeas.gif \organic\vegetables\legumes\ 2007-07- +1613:55:06.000000

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: MultiLine Tables into Variables by BrowserUk
in thread MultiLine Tables into Variables by Knoperl

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.