Corion's solution looks very interesting, and now that I've seen it, I might try that first. Had I not seen that, my first instinct would have been to rely on the apparently consistent "syntactic" cues in your example, and process the data line-by-line, using known expectations:

  1. When I see /Transaction\s+Employee\s+-{3}\s/ I know the next two lines will complete the display of column headings.

  2. Having reached the end of the headings, the next line contains your "Code1/.../Code2" string; that's easy enough.

  3. After that, lines matching /^\s*\d{1,2}-[A-Z]{3}-\d{2}\s+.*?\s\d+\.\d{2}\s*$/ contain column data, and lines matching /^\s{10,}(.*)/ (if any) contain continuation data for the middle column;¹ these latter need to be contiguous with (directly after) the former, and the continuation is terminated by a blank line.

  4. Once a blank line is followed by something that doesn't match the 3-column data pattern, that's the end of the table.

So it's just a fairly well-constrained state machine: watch for start of headings, then get "code" fields, then iterate through sets of row data (3-column line, 0-or-more continuation lines, blank line); when that iteration is done, go back to watching for start of headings.

¹ update: Counting initial whitespace characters on the continuation lines might be tricky, if the input uses tabs and spaces in funny or inconsistent ways.


In reply to Re: Converting a fixed-width report to an Excel-friendly format by graff
in thread Converting a fixed-width report to an Excel-friendly format by loris

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.