Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search block of texts and return the content without it

Status
Not open for further replies.

svij

Programmer
Jan 29, 2012
4
0
0
I have a file that contain multiple text blocks. This block of text will be enclosed by block separators. For Eg. Below is the a sample text block file

<<begin>>
Oracle error occured
ORA-023233 - error message
ORA-023232
<<end>>
<<begin>>
PL-03434 - error message
ORA-023232
<<end>>

The above file that conatins the block of text that needs to be serached in a log file. A log file contains these blocks and additional data. If the log file contain any of the above block, then it need to be skipped and return only the file content without having
the above blocks. Could you please help me.
Thanks in advance
santhu
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Well the very simplistic approach is:

Code:
cat -n alert.log | egrep -v "ORA-023233||PL-03434" |more

The cat -n puts line numbers so you can go back and find your info
if needed, egrep -v is to filter out the words in between the double quotes, and more allows you to page through ....

Just add more filters with the ||<somestring>||<somestring> between the double quotes in egrep.

There is a script somewhere on the web that basically allows you to mark and selectively filter out blocks of text as you go, can't lay my hands on it just now but I remember it requires the Unix "less" command which was never on my Solaris so never really bothered too much.

But with a bit of thought you could pull together a bit of awk/nawk

Laurie
 
Iam new to the unix shell scripting and the person who was taking are of unix shell left. So i started learning it.
earlier the requinrement was to just remove one of the error message from the log file and i created the below entry in the script . the exception_log file was contaning ony one line of text. That was working . But now the requiremnt shifted to multiple line of message blocks.

cat $logfile |egrep -vf ${exptio_file}

It looks hard for me to find a good tutorial of sed/awk and put it for them tomorrow.
It will also be a great help for me to give a good url of awk/sed tutorial

Thanks in advance
 
the issue is if the log file contains the below block of text , then ignore it(we can ignore spaces or tab) . If it contain only a portion of it , then we should not skip it.

Oracle error occured
ORA-023233 - error message
ORA-023232

Similarly there will be multiple error message blocks. So we need to skip all those error message blocks and return the rest of the text data from the log file

Thanks in advance
santhu
 
Something like this?

Code:
awk '
        [gray]# accumulate messages in an array[/gray]
        { a[++i]=[blue]$0[/blue] }
        [gray]# set variable if we found a message to be ignored[/gray]
        [green]/^(Oracle error occurred|ORA-02323[23]|PL-03434)/[/green] { found=1 }
        [gray]# at the end of the block[/gray]
        [green]/<<end>>/[/green] {
                [gray]# only print array contents if ignored message was not found[/gray]
                [olive]if[/olive] (!found) {
                        [olive]for[/olive] (j=1;j<=i;j++) [b]print[/b] a[j]
                }
                [gray]# reset found flag and array index[/gray]
                found=i=0
        }
' inputfile


Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
The log file where the tex to be searched will be like below text.
----------------------------------------------

SV=0 C=-121212 T=saple E=201210 : : Tue Jan 3 23:22:29 2012 datevalchkCursor(in_date) : ORA-01839: date not valid for month specified
ORA-06512: at "RD.prcschktype", line 4567
ORA-06512: at line 1
==> (888 ) : datevalchkCursor(in_date) : ORA-01839: date not valid for month specified
ORA-06512: at "RD.prcschktype

SV=0 C=-121212 T=saple E=201211 : completed successfully
SV=0 C=-121212 T=saple E=201212 : completed successfully
SV=0 C=-121212 T=saple E=201213 : completed successfully
SV=0 C=-121212 T=saple E=201214 : completed successfully

SV=0 C=-121212 T=saple E=201215 : : Tue Jan 3 23:22:29 2012 datevalchkCursor(in_date) : ORA-01839: date not valid for month specified
ORA-06512: at "RD.prcschktype", line 4567
ORA-06512: at line 1
==> ((888 ) : datevalchkCursor(in_date) : ORA-01839: date not valid for month specified
ORA-06512: at "RD.prcschktype

SV=0 C=-121215 T=maple E=201217 : completed successfully
SV=0 C=-121216 T=aples E=201218 : completed successfully
SV=0 C=-121217 T=asaple E=201219 : completed successfully
SV=0 C=-121218 T=sapple E=201220 : completed successfully

SV=0 C=-121212 T=saple E=201210 : : Tue Jan 3 23:22:29 2012 dataval(inVal1,inVal2) : Err 62007: SQL Error: 99999 ORA-24338: Statement Handle not Executed
ORA-06512: at "prto.dttype", line 67475
ORA-06512: at line 1
==> ((888 ) : dataval(inVal1,inVal2) : ORA-24338: statement handle not executed
ORA-06512: at "prto.dttype

SV=0 C=-5657 T=maple E=201217 : completed successfully
SV=0 C=-8901 T=aples E=201218 : completed successfully
SV=0 C=787977 T=asaple E=201219 : completed successfully
SV=0 C=787977 T=sapple E=201220 : completed successfully

getData(io_val) : ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "rd.dataret", line 116
ORA-06512: at line 1
==> ((888 ) : getData(io_val) : ORA-01422: exact fetch returns

V=0 C=-56579 T=maplew E=201217 : completed successfully
SV=0 C=-8905 T=aplesd E=201218 : completed successfully
SV=0 C=787974 T=asaplef E=201219 : completed successfully
SV=0 C=787976 T=wasappl E=201220 : completed successfully


Below is the exception file that conatins the text blocks that needs to be searched in the log file.
---------------------------------------------------------

<<BEGIN>>
datevalchkCursor(in_date) : ORA-01839: date not valid for month specified
ORA-06512: at "RD.prcschktype", line 4567
ORA-06512: at line 1
==> (888 ) : datevalchkCursor(in_date) : ORA-01839: date not valid for month specified
ORA-06512: at "RD.prcschktype
<<BEND>>
<<BEGIN>>
ORA-24338: Statement Handle not Executed
ORA-06512: at "prto.dttype", line 67475
ORA-06512: at line 1
==> ((888 ) : dataval(inVal1,inVal2) : ORA-24338: statement handle not executed
ORA-06512: at "prto.dttype
<<END>>

--------------------------------

The expected output is the lines in the log files, other than the lines that contains the blocks of text in the exception file

thanks in advance
santhu
 
Ah, yes, hmm, sorry, misunderstood your original requirements. Thinking...

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
I'd suggest a brute force approach in perl, since it's much easier to handle multi-line regular expressions. Load the exceptions file up into an array, each array item containing a multi-line exception. Then load (slurp) the entire log file into memory and iterate through the array of exceptions doing a search and replace on the log data. Then write the log data out again.

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
awk '/ORA-023233/ {flag=1;next} /PL-03434/{flag=0} flag {print}'



Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top