Selectively parsing log files using Java

Posted by GPX on Stack Overflow See other posts from Stack Overflow or by GPX
Published on 2011-01-10T09:47:19Z Indexed on 2011/01/10 11:53 UTC
Read the original article Hit count: 197

Filed under:
|
|
|
|

I have to parse a big bunch of log files, which are in the following format.

SOME SQL STATEMENT/QUERY

DB20000I  The SQL command completed successfully.

SOME OTHER SQL STATEMENT/QUERY

DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.

EDIT 1: The first 3 lines (including a blank line) indicate an SQL statement executed successfully, while the next three show the statement and the exception it caused. darioo's reply below, suggesting the use of grep instead of Java, works beautifully for a single line SQL statement.

EDIT 2: However, the SQL statement/query might not be a single line, necessarily. Sometimes it is a big CREATE PROCEDURE...END PROCEDURE block. Can this problem be overcome using only Unix commands too?

Now I need to parse through the entire log file and pick all occurrences of the pair of (SQL statement + error) and write them in a separate file.

Please show me how to do this!

© Stack Overflow or respective owner

Related posts about java

Related posts about regex