Search pattern on logfile and search for day/dates and skip duplicate lines if any


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search pattern on logfile and search for day/dates and skip duplicate lines if any
# 1  
Old 06-07-2014
Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi,

I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error.

Unfortunately, this is not a fool proof script. I assumed that if the ORA- error appears on line n. line n-1 is where the .trc line is and n-2 is the date.

Below is an excerpt of the script.

Code:
grep -in "$error_to_search" $alert_log | tee -a $tmp_01

...
...
...

   while read line
   do
      line_err=`echo $line | awk -F":" '{ print $1 }'`
      let line_trc=$line_err-1
      let line_date=$line_err-2
      tracefile=`sed -n "${line_trc}p" $alert_log | awk '{ print $4 }' | awk -F":" '{ print $1 }'`
...
...
...

         sed -n "${line_date}p" $alert_log
         sed -n "${line_trc}p" $alert_log
         sed -n "${line_err}p" $alert_log


...
...
...
   done < $tmp_01

An excerpt of the $alert_log below is as below. The assumption of the error line, dateline, tracefile line is correct on the first three (3) ORA- errors but not on the fourth one, the one in RED.

Since the 4th one happens immediately after the 3rd one, it should be considered as to have occurred on the same date and can be ignored. To get it to work, if the ORA- error line are consecutive, it should only consider the first one and ignore the others but I don't know how to do this?

Code:
Wed May 28 14:35:56 2014
Errors in file /db/abcd/dba/udump/abcd_ora_28306.trc:
ORA-01017: invalid username/password; logon denied
Wed May 28 14:39:59 2014
Errors in file /db/abcd/dba/udump/abcd_ora_4506.trc:
ORA-01017: invalid username/password; logon denied
Wed May 28 14:43:30 2014
Errors in file /db/abcd/dba/udump/abcd_ora_4506.trc:
ORA-01017: invalid username/password; logon denied
ORA-01017: invalid username/password; logon denied
Wed May 28 15:11:25 2014
Thread 1 advanced to log sequence 51621 (LGWR switch)
  Current log# 4 seq# 51621 mem# 0: /db/abcd/redolog/abcd_redo_4a.dbf
  Current log# 4 seq# 51621 mem# 1: /db/abcd/mirrlog/abcd_redo_4b.dbf

In summary, what I am hoping to achieve with the script is:

01 - Search for a specific ORA- errors and print that line, i.e. line n.
02 - Search backward and search for the tracefile/.trc file, that should be the tracefile associated to this error. At the moment I am assuming this is line n-1. How do I search from line n backward and print the line that has the .trc line?
03 - Search backward for the first dateline and that should be the date when this ORA- error occurred. At the moment, I am assuming this is line n-2. How do I search from line n backward and print the first dateline? From the excerpt, the dateline format starts with day of the week, Mon [Month] [Day], Tue [Month] [Day], Wed [Month] [Day] etc.
# 2  
Old 06-07-2014
- FYI, x.txt is the script that I have so far.

Last edited by newbie_01; 06-07-2014 at 07:19 PM..
# 3  
Old 06-07-2014
Not sure I understand your spec entirely, but to print the ORA errors with their associated date and .trc file, try
Code:
 awk '$5=='2014'{DATE=$0} /.trc:$/{TRC=$0} $0 ~ PAT {print DATE; print TRC; print}' PAT="ORA-01017"  file4

The date identification part might benefit from a bit sophistication...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search for word in huge logfile and need to continue to print few lines from that line til find date

Guys i need an idea for one logic..in shell scripting am struggling with a logic...So the thing is... i need to search for a word in a huge log file and i need to continue to print few more lines from that line and the consecutive line has to end when it finds the line with date..because i know... (1 Reply)
Discussion started by: Prathi
1 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

sed search pattern and delete lines

Hello, i have a question. My problem is that i have a file like: TEST JOHN ADAM MICHAEL SEBASTIAN ANDY i want find for MICHAEL and want delete lines like this: TEST (4 Replies)
Discussion started by: eightball
4 Replies

4. Shell Programming and Scripting

How to search for pattern in odd lines?

Hi friends, I am looking for sed command/script that would search for a given fixed pattern on odd lines and then if it matches, prints the matching pattern and the next line. For example, in the example below, i am looking for pattern 0 and 1011 on odd lines. ########## start of example file... (10 Replies)
Discussion started by: kaaliakahn
10 Replies

5. Shell Programming and Scripting

search pattern and read lines

Hi, I have a huge de-limited file which has pattern : 99"9876"2010-11-21 12:51:01"J"MNOPQRS ID# 2-1234-1234-0099-9876-0 "" <<read>> 99"9876"2010-11-21 12:51:01"K"R-EMP# 01234567 (LOGOFF) "" <<read>> 99"9876"2010-11-21 12:51:01"L" *AUTO LOGOFF* ... (3 Replies)
Discussion started by: angie1234
3 Replies

6. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

7. Shell Programming and Scripting

read lines between search pattern

I have a file split something like 01/11/2010: No of users 100 02/11/2010: No of users 102 03/11/2010: No of users 99 ... I want to search the file for a particular date and then extract the following line with the date, something like 02/11/2010 No of users 102 I can grep... (6 Replies)
Discussion started by: gefa
6 Replies

8. Shell Programming and Scripting

Pattern search in multiple lines

Hi, I have to search those statements from the file which starts from "shanky"(only shanky, shanky09 or 09shanky is not allowed) and ends with ");". These two string can be in a same line or different line. And also i have to negate those lines which starts with #. Can any one please give me... (2 Replies)
Discussion started by: shanky09
2 Replies

9. UNIX for Dummies Questions & Answers

Print lines between the search pattern

hi, I have a file say x.txt containing xxx 123 bla bla ... you xxx dfk dbf ... me xxx ... ... keeps on.. i need to search for pattern in the line starting xxx in the file. If pattern matched, I need to fetch all the lines till i find next xxx. (17 Replies)
Discussion started by: prsshini
17 Replies

10. Shell Programming and Scripting

Search file for pattern and grab some lines before pattern

I want to search a file for a string and then if the string is found I need the line that the string is on - but also the previous two lines from the file (that the pattern will not be found in) This is on solaris Can you help? (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question