Hello all,

I have been given what seems to me a slightly hairy task. I have a report with fixed-width fields similar to this:

Line containing uninteresting information Another line containing uninteresting information More uninteresting information Transaction Employee --- Date Name Amount ------------ ------------------ 111/222/ABC 23-JAN-06 Baker, Abel 111.11 24-JAN-06 Baker, Abel 222.22 25-JAN-06 Baker, Abel 333.33 26-JAN-06 Baker, Abel 444.44 27-JAN-06 Baker, Abel 555.55 Line containing uninteresting information Another line containing uninteresting information Transaction Employee --- Date Name Amount ------------ ------------------ 333/444/DEF 23-JAN-06 Dog, 111.11 Charlie 24-JAN-06 Dog, 222.22 Charlie 25-JAN-06 Dog, 333.33 Charlie

Note the spurious ^L characters, which appear as boxes in my browser, at the beginning of some lines and the over-wide fields running into the following line.

This needs to be converted to Excel-readable format, e.g. CSV, containing the information from the table-like parts with information from the line after the headers in additional colums, like this:

Code1|Code2|Transaction Date|Employee Name|Amount 111|ABC|23-JAN-06|Baker, Abel|111.11 111|ABC|24-JAN-06|Baker, Abel|222.22 111|ABC|25-JAN-06|Baker, Abel|333.33 111|ABC|26-JAN-06|Baker, Abel|444.44 111|ABC|27-JAN-06|Baker, Abel|555.55 333|DEF|23-JAN-06|Dog, Charlie|111.11 333|DEF|24-JAN-06|Dog, Charlie|222.22 333|DEF|25-JAN-06|Dog, Charlie|333.33

I would approach this in the following way

Does any one have any less naive ideas? I wondered whether there is there something like format for reading files?

Thanks,

loris


"It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."

In reply to 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.