periodicalcoder has asked for the wisdom of the Perl Monks concerning the following question:
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.
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...):perl -nle "print if /\QLX*\E/ .. /\QCAS*\E/" "filename"
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
|
|---|