bp4a has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex to end of a line from previous line
by Corion (Patriarch) on Sep 23, 2010 at 15:12 UTC | |
by bp4a (Initiate) on Sep 23, 2010 at 15:28 UTC | |
by Corion (Patriarch) on Sep 23, 2010 at 15:30 UTC | |
|
Re: Regex to end of a line from previous line
by moritz (Cardinal) on Sep 23, 2010 at 15:18 UTC | |
|
Re: Regex to end of a line from previous line
by kennethk (Abbot) on Sep 23, 2010 at 15:39 UTC | |
by bp4a (Initiate) on Sep 23, 2010 at 16:17 UTC |