How to read multiple line from log file

I have errors in the log that span multiple lines and I can find say the 2nd line in the log of this error using an unique word. However, this only gets me the line that the word appears in not the full error which may be 3 or four line long. So if there way to display say the line before a match and after a match. Any idea guys?

Thanks in advance.

be precise by giving an example

for example here is some text of log file

2008-11-24 07:25:41,677 INFO (main - txUID5c4os1l-l4zigw-fnwsocop-1-fnwsocoq-2) [ZeroConfRegistry] Starting ZC-Service-Monitor with initalwait=5000 and interval= 5000
2008-11-24 07:25:44,114 INFO (main - txUID5c4os1l-l4zigw-fnwsocop-1-fnwsocoq-2) [Embedded] Catalina naming disabled
2008-12-16 21:29:33,860 ERROR (adPoolWorker[1] - txUID5c4os1l-l4zigw-fnwsocop-1-fnwsx74u-9) [AbstractIndexBuilder] SEARCHE0129 problem rebuilding index
com.lastminute.u2search.index.IndexException: problem reading source
at com.lastminute.u2search.index.tree.stored.StoredTreeIndexBuilder.index(StoredTreeIndexBuilder.java:129)
at com.lastminute.u2search.index.tree.stored.StoredTreeIndexBuilder.rebuild(StoredTreeIndexBuilder.java:87)
at com.lastminute.u2search.index.builder.AbstractIndexBuilder.runScheduledTask(AbstractIndexBuilder.java:68)
at com.lastminute.u2search.util.Scheduler.runPendingTasks(Scheduler.java:91)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
Caused by: com.lastminute.u2search.source.SourceException: org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (java.sql.SQLException: No connections are allowed in quiescent mode.); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: No connections are allowed in quiescent mode.))
2008-12-16 21:32:30,943 INFO (adPoolWorker[1] - txUID5c4os1l-l4zigw-fnwsocop-1-fnwsx74u-9) [LocationRelationshipIndexBuilder] SEARCHI0022 at 10 records...

keep on going.......................

So what i want is to grep and ERROR, but if i grep error <file name> then it will display only one line of error.
i want to place a logic so that starting from line ERROR until INFO i was all the lines.. like

2008-12-16 21:29:33,860 ERROR (adPoolWorker[1] - txUID5c4os1l-l4zigw-fnwsocop-1-fnwsx74u-9) [AbstractIndexBuilder] SEARCHE0129 problem rebuilding index
com.lastminute.u2search.index.IndexException: problem reading source
at com.lastminute.u2search.index.tree.stored.StoredTreeIndexBuilder.index(StoredTreeIndexBuilder.java:129)
at com.lastminute.u2search.index.tree.stored.StoredTreeIndexBuilder.rebuild(StoredTreeIndexBuilder.java:87)
at com.lastminute.u2search.index.builder.AbstractIndexBuilder.runScheduledTask(AbstractIndexBuilder.java:68)
at com.lastminute.u2search.util.Scheduler.runPendingTasks(Scheduler.java:91)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
Caused by: com.lastminute.u2search.source.SourceException: org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (java.sql.SQLException: No connections are allowed in quiescent mode.); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: No connections are allowed in quiescent mode.))

I hope i am clear now.

If you are sure that the error lines will always have an INFO at the end, you may use:

awk '/ERROR/,/INFO/{ if( $0 !~ /INFO/ )print }' infile
1 Like

Thanks lot its really nice awk....
But you are right i have WARNING also in between in the file.
I tried with the command like this

awk '/ERROR/,/INFO/||/WARNING/{ if( $0 !~ /INFO/ || /WARNING/ )print }' infile

But getting warning line also in output, any idea, am i missing anything?