How to read multiple line from log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read multiple line from log file
# 1  
Old 01-29-2009
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.

Last edited by otheus; 01-29-2009 at 06:59 AM.. Reason: removed strange javascript links
# 2  
Old 01-29-2009
be precise by giving an example

be precise by giving an example
# 3  
Old 01-29-2009
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:1 29)
at com.lastminute.u2search.index.tree.stored.StoredTreeIndexBuilder.rebuild(StoredTreeIndexBuilder.java :87)
at com.lastminute.u2search.index.builder.AbstractIndexBuilder.runScheduledTask(AbstractIndexBuilder.jav a:68)
at com.lastminute.u2search.util.Scheduler.runPendingTasks(Scheduler.java:91)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.ObjectSmilieLjava.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:1 29)
at com.lastminute.u2search.index.tree.stored.StoredTreeIndexBuilder.rebuild(StoredTreeIndexBuilder.java :87)
at com.lastminute.u2search.index.builder.AbstractIndexBuilder.runScheduledTask(AbstractIndexBuilder.jav a:68)
at com.lastminute.u2search.util.Scheduler.runPendingTasks(Scheduler.java:91)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.ObjectSmilieLjava.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.
# 4  
Old 01-29-2009
If you are sure that the error lines will always have an INFO at the end, you may use:
Code:
awk '/ERROR/,/INFO/{ if( $0 !~ /INFO/ )print }' infile

This User Gave Thanks to skar_a For This Post:
# 5  
Old 01-30-2009
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Read in Multiple log files and output selected variables and values to cvs file

I have several problems with my problems: I hope you can help me. 1) the If else statement I am getting an error message. My syntax must be incorrect because the entire statement is throwing an error. For example in filew.log if these items don't exist Memsize, SASFoundation and also if... (0 Replies)
Discussion started by: dellanicholson
0 Replies

2. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

3. Shell Programming and Scripting

HELP: Shell Script to read a Log file line by line and extract Info based on KEYWORDS matching

I have a LOG file which looks like this Import started at: Mon Jul 23 02:13:01 EDT 2012 Initialization completed in 2.146 seconds. -------------------------------------------------------------------------------- -- Import summary for Import item: PolicyInformation... (8 Replies)
Discussion started by: biztank
8 Replies

4. Shell Programming and Scripting

Shell script to read multiple options from file, line by line

Hi all I have spent half a day trying to create a shell script which reads a configuration file on a line by line basis. The idea of the file is that each will contain server information, such as IP address and various port numbers. The line could also be blank (The file is user created). Here... (1 Reply)
Discussion started by: haggismn
1 Replies

5. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (1 Reply)
Discussion started by: erlanq
1 Replies

6. Shell Programming and Scripting

read one line file and separate into multiple lines

I have one long line text with semicolon used as separator between values in that line. Now, I want to separate the line into multiple line right after every 29th field. example input line: ... (2 Replies)
Discussion started by: erlanq
2 Replies

7. Shell Programming and Scripting

Read 1-line file and separate into multiple variables

I have one line files with 17 records separated by a semi-colon. I need to create a variable from each record, which I can do via a separate awk for each one, but I know there has to be a better way. Along with pulling out the variable, I need to convert some url coding like a + to a space, etc.... (4 Replies)
Discussion started by: numele
4 Replies

8. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

Read multiple log files and create output file and put the result

OS : Linux 2.6.9-67 - Red Hat Enterprise Linux ES release 4 Looking for a script that reads the following log files that gets generated everynight between 2 - 5am Master_App_20090717.log Master_App1_20090717.log Master_App2_20090717.log Master_App3_20090717.log... (2 Replies)
Discussion started by: aavam
2 Replies

10. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies
Login or Register to Ask a Question