Thanks in advance for any and all assistance. My issue is I want to parse through a text file and get a SQL error message, I can get the regex to match on the "SQL" but then I want to capture the message to the end of the next line. Here is my code so far:

while (my $line = <FILE>) { if($line =~ /SQL/) { chomp($date = `date`); chomp ($errcode = $line); print ERR "$date - $errcode\n"; } }

Here is a sample input file:

Sun Sep 19 10:34:29 2010
Online Backup for GMT failed.
SQL2033N An error occurred while accessing TSM during the processing of a
database utility. Reason code: 1.

So what I want returned is:
SQL2033N An error occurred while accessing TSM during the processing of a
database utility. Reason code: 1.

So I can match and return the line that has "SQL" but I can't figure out how to return the line underneath it becuase that line doens't have anything consistent, in fact there may not even be anything on that line depending on the error.

I just can't figure out how to get this to return the next line in the file to the end of that line along with the line that I matched with the REGEX.

Thanks -- bp4a


In reply to Regex to end of a line from previous line by bp4a

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.