Thanks for a very clear statement of the goal. Many here would also be grateful to see what sort of code you have tried, so we could see if your problems are few or many...

In any case, the solution would depend on how easy it is to identify boundaries between consecutive records, given that each record consists of multiple lines with rather intricate white-space formatting. The example suggests that each new record begins with this sort of pattern, which can be used to capture this part of the info for the report:

/^(BCG-\d+)/ # i.e. line-initial "BCG-" followed by digits
and that the "SNBX" and "TRX" records always follow line-initial whitespace, so they can be captured as follows:
/^\s+(SNBX\S+)/ /^\s+(TRX-\d+)\s+\S+\s+BL-TRX/
If those assumptions hold, then the logic could go something like this (not tested):
print "BCG LOCATION TRX STATUS\n"; print "---------------------------------\n"; while (<>) { if (/^(BCG-\d+)/) { # start of record $recid = $1; $loc = $trx = $stat = ""; } elsif (/^\s+(SNB\S+)/) { $loc = $1; } elsif (/^\s+(TRX\S+)\s+\S+\s+(BL-TRX)/) { print "$recid $loc $1 $2\n"; } }
That would probably need some tweaking to get the column alignments right -- you could try the FORMAT mechanism (which I never really got the hang of) or the printf function (which I've been hooked on since cutting my teeth in C years ago).

In reply to Re: Newbie Needs Help! by graff
in thread Getting a Human Readable Report from a data file by gargs

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.