First time poster on this forum. I periodically write scripts to parse data or to reduce server administration effort. Typically I write batch (ouch) or bash, and I have only written perl scripts a few times.

In this case I have spent a couple of hours looking for a solution to this and so far I have not had much luck, or I may not have understood the solutions that I had found. I am trying to match a range of lines, but only print the matching lines to a file if there is a specific string inside the initial match. I need to run this script on Windows (currently using Strawberry Perl), and I may end up handing the script to a non-technical user after setting up the environment to allow it to run.

This script successfully grabs data when only defining the beginning and end string match.

perl -nle "print if /\QLX*\E/ .. /\QCAS*\E/" "filename"
Here is an example of the source file (UPDATE: added the proceeding text on the "00003" lines. I'm embarrassed that I missed this as I somehow didn't think it would matter...):
LX* other data SVC*HC:00003 other data CAS* LX* other data SVC*HC:00001 other data CAS* LX* other data SVC*HC:00003 other data CAS*

Could someone point me in the right direction for how to print the matching range, between "LX* and CAS*", to a file only if the string "00003" exists within that range? So long as it can be run in Windows I am open to suggestions.

Thank you very much for your assistance. This script could potentially help save quite a lot of time on a weekly basis.

Sean

In reply to Matching range of text with another string in between by periodicalcoder

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.