I have some large data sets that have oddly formatted lines, and much of it I don't need. The general rule is that I need to keep every instance of lines that start with "john#", are followed by {2,5}new lines, and then lines starting with "jacob - \d\.0"

bhgfsggdsgsg -- john1 weruwearnwrnweuarar jjafdaiuweifweofiuwe jacob - 1.0 -- nfaslf23523525 john2 asfsjldf43tgre john3 asbdfhskafbv3333v sdfahh34ttg sadfhk34t3wtg sdfhk3gfwghhw3 jacob - 2.0

The output that I need would look like this..

john1 > jacob - 1.0 john3 > jacob - 2.0

Obviously my data is a little different than this, but I have every regex pulling exactly what I need, but just not in the way I want it. I can't seem to figure out how to tell it to take John# only when followed by a Jacob. I don't want to keep a John# unless it is followed by a Jacob. For instance, the code below would look at when there are 3 lines between them...I know it isn't right, but the multi-match, multi-line thing has me confused.

if($line1 =~ /(john)^.{1,100}$^.{1,100}$^.{1,100}$^(jacob \- \d\.0)/s) { ($JOHN,$JACOB) = ($1,$2); print MYOUTPUTFILE1 "$JOHN - $JACOB"; }

In reply to Matching consecutive "different" regex patterns across multiple lines by eh3civic

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.