Script to capture string in a log file

Dear all,

I have a log file to be analysed. this log file contains vaiours lines of code starting with date timestamp.

if my search string is exception then that resepective log statement starting from the date is required.

example:

2014/10/01 16:14:44.459|>=|E|X|19202496|2832| |||||||||||||||Uncaught
Exception in SilentScope: CDZServerFactory::newService(const CORBA_WChar *, const CORBA_WChar *): 0.002
cefactory.cpp:163: TraceLog message 2
2014/10/01 16:14:46.475|>=|E|X|19202496|5410| |||||||||||||||Uncaught
Exception in SilentScope: CDZServerFactory::newService(const CORBA_WChar *, const CORBA_WChar *): 0.001
WebIDocAutoSaveMgrImpl.cpp:615: TraceLog message 3
2014/10/01 16:47:00.564|>>|E| |19202496|7731|
|||||||||||||||**ERROR:WebIDocAutoSaveMgrImpl:WebIDocAutoSaveMgrImpl::CreateBackupFolder: Unable
to create Backup folder : [repo_proxy 24] FolderFacade::manageFolder -
(Helpers::InfoStore::Query::getObjectWithWhereClause) ISInfoObject has
not been found [WebIDocAutoSaveMgrImpl.cpp;615]
WebIDocAutoSaveMgrImpl.cpp:541: TraceLog message 4
2014/10/01 16:47:00.564|>=|E|X|19202496|7731| |||||||||||||||Uncaught
Exception in SilentScope: WebIDocAutoSaveMgrImpl:CreateBackupFolder:

out of these 4 logs statements, only the 3 needs to be retrieved.

can you please help me to advise what would be best way to write a script for this.

please note that the word exception should pull in the complete log statement which is contained in 4 lines.

--shravee

Welcome to forums please show expected output as well

And what code have you tried thus far? Please post it so we can help you.

===== contents in the log file ======

2014/10/01 16:14:44.459|>=|E|X|19202496|2832| |||||||||||||||Uncaught
Exception in SilentScope: CDZServerFactory::newService(const CORBA_WChar *, const CORBA_WChar *): 0.002
cefactory.cpp:163: TraceLog message 2
2014/10/01 16:14:46.475|>=|E|X|19202496|5410| |||||||||||||||Uncaught
Exception in SilentScope: CDZServerFactory::newService(const CORBA_WChar *, const CORBA_WChar *): 0.001
WebIDocAutoSaveMgrImpl.cpp:615: TraceLog message 3
2014/10/01 16:47:00.564|>>|E| |19202496|7731|
|||||||||||||||**ERROR:WebIDocAutoSaveMgrImpl:WebIDocAutoSaveMgrImpl::CreateBackupFolder: Unable
to create Backup folder : [repo_proxy 24] FolderFacade::manageFolder -
(Helpers::InfoStore::Query::getObjectWithWhereClause) ISInfoObject has
not been found [WebIDocAutoSaveMgrImpl.cpp;615]
WebIDocAutoSaveMgrImpl.cpp:541: TraceLog message 4
2014/10/01 16:47:00.564|>=|E|X|19202496|7731| |||||||||||||||Uncaught
Exception in SilentScope: WebIDocAutoSaveMgrImpl:CreateBackupFolder

======== expected output =========

2014/10/01 16:14:44.459|>=|E|X|19202496|2832| |||||||||||||||Uncaught
Exception in SilentScope: CDZServerFactory::newService(const CORBA_WChar *, const CORBA_WChar *): 0.002
cefactory.cpp:163: TraceLog message 2
2014/10/01 16:14:46.475|>=|E|X|19202496|5410| |||||||||||||||Uncaught
Exception in SilentScope: CDZServerFactory::newService(const CORBA_WChar *, const CORBA_WChar *): 0.001
WebIDocAutoSaveMgrImpl.cpp:615: TraceLog message 3
2014/10/01 16:47:00.564|>=|E|X|19202496|7731| |||||||||||||||Uncaught
Exception in SilentScope: WebIDocAutoSaveMgrImpl:CreateBackupFolder

so what i need is a script file that can read the contents of this log file and produce a output as expected.

--shravee

I am not having access to a machine right now so cant test a code but my logic would be something like this:

  1. Loop on the file line by line
  2. Add the line to an array by default
  3. Continue adding the lines until you reach a line that starts with date.
  4. At this point analyze if the existing lines in the array have exception word in it or not
  5. If yes then print it to output file and flush the array and add next line to it
  6. If no then flush the array and add next line to it

if each log record in spanned across multiple lines,

awk '/^[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9] [0-9][0-9]:/ {print "\n" $0}' file.log | awk '/Exception/' RS=