1753889 Members
7762 Online
108809 Solutions
New Discussion юеВ

Script help

 
SOLVED
Go to solution
Prashant Zanwar_4
Respected Contributor

Script help

Hi,
I want a script which will get for a pattern, and depending on Line number pattern, will display 4Lines above the line and 4Line Below that line. I am finding it challening!
Thanks in advance
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
11 REPLIES 11
Tom Schroll
Frequent Advisor

Re: Script help


Prashant,

Could you send an example of input and what you would like to see on output? How big is the input data file (under 2GB?) I'm thinking awk can do this using arrays. But I'd like an example so that it is clear what we are trying to do. Thanks!

-- Tom
If it ain't broke, it needs optimized.
Prashant Zanwar_4
Respected Contributor

Re: Script help

I am trying to Trace oracle errors, Just want to check for particular ora error, few lines before that and few lines after it.
Thanks and regards
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Sandman!
Honored Contributor

Re: Script help

What would be a good example of the oracle error you are trying to extract from the file. A concrete example will help.

cheers!
Prashant Zanwar_4
Respected Contributor

Re: Script help

Completed: drop rollback segment RB31
Fri Aug 12 05:34:56 2005
drop rollback segment RB32
Completed: drop rollback segment RB32
Fri Aug 12 05:36:08 2005
drop tablespace RBS
Fri Aug 12 05:36:36 2005
Errors in file /oracle/admin/COREPROD/bdump/coreprod_j002_7027.trc:
ORA-12012: error on auto execute of job 137728
ORA-01405: fetched column value is NULL
ORA-06512: at "SYS.DBMS_AQADM_SYS", line 5636
ORA-06512: at "SYS.DBMS_AQADM_SYS", line 6061
ORA-06512: at "SYS.DBMS_AQADM", line 895
ORA-06512: at line 1
Fri Aug 12 05:36:36 2005
Errors in file /oracle/admin/COREPROD/bdump/coreprod_j001_7025.trc:

Here are errors pasted.
While these errors can be many in file, if provision can be made to see from recent dates of 2-3 days will be great.
Thanks
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Mel Burslan
Honored Contributor
Solution

Re: Script help

FILE=filename.here
PATTERN="string_here"
for lineno in `grep -n $PATTERN $FILE|cut -d: -f1`
do
(( TOP=$lineno-5 ))
(( BOT=$lineno+5 ))
cat $FILE | sed -e "${BOT},\$d" | sed -e "1,${TOP}d"
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" # block separator
done


this should do the trick.. even for multiple instances of the same string repeating in the source file.

HTH
________________________________
UNIX because I majored in cryptology...
Sandman!
Honored Contributor

Re: Script help

If you're trying to capture 4-5 lines above/below the "ORA-06512" errors that are popping up in your trace file then a short script like the one below will do what you are interested in accomplishing:

=============================================
# cat - <> /ORA-06512/-4,/ORA-06512/+4 p
> wq
> EOF
=============================================

cheers!!!

Sandman!
Honored Contributor

Re: Script help

Change the "wq" to "q" as you're not writing the output to a file.
Prashant Zanwar_4
Respected Contributor

Re: Script help

Thanks you both, 1st soluion by Mel is working !
While I dont find 2nd solution from Sandman not working, basically whole file is scrolling..AM I doing anything wrong.
Prashant
"Intellect distinguishes between the possible and the impossible; reason distinguishes between the sensible and the senseless. Even the possible can be senseless."
Sandman!
Honored Contributor

Re: Script help

Prashant,

I tested this code on your trace file and it worked fine. But, I'm not sure why its not working on yours.

Try this one and replace string ORA-6512 with actual pattern you are searching for:

# ex -s <> /ORA-06512/-4,/ORA-06512/+4 p
> EOF