Sponsored Content
Top Forums Shell Programming and Scripting Search pattern on logfile and search for day/dates and skip duplicate lines if any Post 302904858 by newbie_01 on Saturday 7th of June 2014 04:02:54 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
LOGSAVE(8)						      System Manager's Manual							LOGSAVE(8)

NAME
logsave - save the output of a command in a logfile SYNOPSIS
logsave [ -asv ] logfile cmd_prog [ ... ] DESCRIPTION
The logsave program will execute cmd_prog with the specified argument(s), and save a copy of its output to logfile. If the containing directory for logfile does not exist, logsave will accumulate the output in memory until it can be written out. A copy of the output will also be written to standard output. If cmd_prog is a single hyphen ('-'), then instead of executing a program, logsave will take its input from standard input and save it in logfile logsave is useful for saving the output of initial boot scripts until the /var partition is mounted, so the output can be written to /var/log. OPTIONS
-a This option will cause the output to be appended to logfile, instead of replacing its current contents. -s This option will cause logsave to skip writing to the log file text which is bracketed with a control-A (ASCII 001 or Start of Header) and control-B (ASCII 002 or Start of Text). This allows progress bar information to be visible to the user on the console, while not being written to the log file. -v This option will make logsave to be more verbose in its output to the user. AUTHOR
Theodore Ts'o (tytso@mit.edu) SEE ALSO
fsck(8) E2fsprogs version 1.44.1 March 2018 LOGSAVE(8)
All times are GMT -4. The time now is 04:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy