How to get lines before and after a searched text?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get lines before and after a searched text?
# 8  
Old 06-28-2012
can i pass the date as a variable.

Code:
awk '/Jun 12 .* 2012.*ORA-07445/'

like
Code:
awk '/$whichdate.*ORA-/'

Please do let me know

Last edited by Scrutinizer; 06-28-2012 at 11:24 AM.. Reason: code tags
# 9  
Old 06-28-2012
You could try like this:
Code:
whichdate="Jun 12 .* 2012"
awk '/^... ... .. ..:..:/{printf RS}{print NR ": " $0}' infile | awk '$0~s' s="${whichdate}.*ORA-07445"  RS=

# 10  
Old 06-28-2012
getting error

Code:
cat t.ksh

#Jun 28 10:18:36 EDT 2012
whichdate="Jun 28 .* 2012"
awk '/^... ... .. ..:..:/{printf RS}{print NR ": " $0}' alert_HRPRD89.log | awk '$0~s' s="${whichdate}.*ORA-07445"  RS=



Code:
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$ ksh -x t.ksh
+ whichdate=Jun 28 .* 2012
+ awk $0~s s=Jun 28 .* 2012.*ORA-07445 RS=
+ awk /^... ... .. ..:..:/{printf RS}{print NR ": " $0} alert_HRPRD89.log
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$ ls -l alert_HRPRD89.log
-rw-r-----    1 oracle   dba         2960095 Jun 28 09:29 alert_HRPRD89.log
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$


Last edited by Scrutinizer; 06-28-2012 at 11:43 AM.. Reason: code tags
# 11  
Old 06-28-2012
Where is the error?
# 12  
Old 06-28-2012
extremely sorry, stupid of me not to see that there is no message in today's log.

i tried with a previous date and it is working fine.

Sir's
thank you all for having patience and helping me out.

Code:
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$ ksh t.ksh
23173: Tue Jun 12 06:57:53 2012
23174: Exception [type: SIGSEGV, Address not mapped to object] [ADDR:0xB38F0000000073] [PC:0x1085CD368, kxhrInit()+136] [flags: 0x0, count: 1]
23175: Errors in file /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace/HRPRD89_ora_5021834.trc  (incident=42033):
23176: ORA-07445: exception encountered: core dump [kxhrInit()+136] [SIGSEGV] [ADDR:0xB38F0000000073] [PC:0x1085CD368] [Address not mapped to object] []
23177: Incident details in: /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/incident/incdir_42033/HRPRD89_ora_5021834_i42033.trc
23178: Use ADRCI or Support Workbench to package the incident.
23179: See Note 411.1 at My Oracle Support for error and packaging details.
23263: Tue Jun 12 07:30:14 2012
23264: Exception [type: SIGSEGV, Address not mapped to object] [ADDR:0xB38F0000000073] [PC:0x1085CD368, kxhrInit()+136] [flags: 0x0, count: 1]
23265: Errors in file /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace/HRPRD89_ora_864458.trc  (incident=42273):
23266: ORA-07445: exception encountered: core dump [kxhrInit()+136] [SIGSEGV] [ADDR:0xB38F0000000073] [PC:0x1085CD368] [Address not mapped to object] []
23267: Incident details in: /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/incident/incdir_42273/HRPRD89_ora_864458_i42273.trc
23268: Use ADRCI or Support Workbench to package the incident.
23269: See Note 411.1 at My Oracle Support for error and packaging details.
you have mail in /usr/spool/mail/oracle
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$

---------- Post updated at 08:22 PM ---------- Previous update was at 08:13 PM ----------

sorry again pestering.
here is one of the output in a file.
i was looking for 3 or 4 lines above and below the searched text.
now when i run the script i see that it is pulling line above it and not the lines below.
plaese do help me out

Code:
ERROR: Unable to normalize symbol name for the following short stack (at offset 224):
dbgexProcessError()+180<-dbgeExecuteForError()+72<-dbgePostErrorKGE()+2048<-dbkePostKGE_kgsf()+68<-kgeadse()+380<-kgerinv_internal()+48<-kgerinv()+48<-
kgeasnmierr()+72<-qkaffsindex()+3960<-qkatab()+10816<-qkajoi()+552<-IPRA.$qkaqkn()+1076<-IPRA.$qkadrv()+1044<-qkadrv()+96<-opitca()+4008<-kksFullTypeCh
eck()+76<-rpiswu2()+480<-kksSetBindType()+6112<-kksfbc()+9648<-opiexe()+1872<-kpoal8()+1856<-opiodr()+720<-kpoodrc()+36<-rpiswu2()+480<-kpoodr()+512<-u
pirtrc()+1328<-kpurcsc()+108<-kpuexec()+3088<-OCIStmtExecute()+32<-qksanExecSql()+1088<-qksanAnalyzeSql()+2144<-qsmmixProcessQuery()+1044<-qsmmixSqlTun
eAnalyzeIdx()+496<-kestsiIndexAnalyzeDrv()+740<-kestsTuneSqlDrv()+912<-kesaiExecAction()+828<-kesaiTuneSqlDrv()+4268<-spefcifa()+408<-spefmccallstd()+3
16<-pextproc()+168<-peftrusted()+164<-psdexsp()+276<-rpiswu2()+480<-psdextp()+632<-pefccal()+588<-pefcal()+260<-pevm_FCAL()+144<-pfrinstr_FCAL()+96<-pf
rrun_no_tool()+96<-pfrrun()+1032
Errors in file /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace/HRPRD89_j000_5021728.trc  (incident=42193):
ORA-00600: internal error code, arguments: [qkaffsindex3], [], [], [], [], [], [], [], [], [], [], []
Incident details in: /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/incident/incdir_42193/HRPRD89_j000_5021728_i42193.trc
Sat Jun 02 06:52:47 2012
Dumping diagnostic data in directory=[cdmp_20120602065247], requested by (instance=1, osid=5021728 (J000)), summary=[incident=42193].
Sat Jun 02 06:52:48 2012
Sweep [inc][42193]: completed


Code:
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$ ksh t.ksh
4398: Sat Jun 02 06:52:42 2012
4399: ERROR: Unable to normalize symbol name for the following short stack (at offset 224):
4400: dbgexProcessError()+180<-dbgeExecuteForError()+72<-dbgePostErrorKGE()+2048<-dbkePostKGE_kgsf()+68<-kgeadse()+380<-kgerinv_internal()+48<-kgerinv()+48<-kgeasnmierr()+72<-qkaffsindex()+3960<-qkatab()+10816<-qkajoi()+552<-IPRA.$qkaqkn()+1076<-IPRA.$qkadrv()+1044<-qkadrv()+96<-opitca()+4008<-kksFullTypeCheck()+76<-rpiswu2()+480<-kksSetBindType()+6112<-kksfbc()+9648<-opiexe()+1872<-kpoal8()+1856<-opiodr()+720<-kpoodrc()+36<-rpiswu2()+480<-kpoodr()+512<-upirtrc()+1328<-kpurcsc()+108<-kpuexec()+3088<-OCIStmtExecute()+32<-qksanExecSql()+1088<-qksanAnalyzeSql()+2144<-qsmmixProcessQuery()+1044<-qsmmixSqlTuneAnalyzeIdx()+496<-kestsiIndexAnalyzeDrv()+740<-kestsTuneSqlDrv()+912<-kesaiExecAction()+828<-kesaiTuneSqlDrv()+4268<-spefcifa()+408<-spefmccallstd()+316<-pextproc()+168<-peftrusted()+164<-psdexsp()+276<-rpiswu2()+480<-psdextp()+632<-pefccal()+588<-pefcal()+260<-pevm_FCAL()+144<-pfrinstr_FCAL()+96<-pfrrun_no_tool()+96<-pfrrun()+1032
4401: Errors in file /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace/HRPRD89_j000_5021728.trc  (incident=42193):
4402: ORA-00600: internal error code, arguments: [qkaffsindex3], [], [], [], [], [], [], [], [], [], [], []
4403: Incident details in: /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/incident/incdir_42193/HRPRD89_j000_5021728_i42193.trc
[oracle@h00dbhris1 /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/trace] [HRPRD89]$


Last edited by Scrutinizer; 06-28-2012 at 11:56 AM.. Reason: code tags
# 13  
Old 06-28-2012
The script prints log entries that contain the search string.. The last line of that entry is
Code:
Incident details in: /apps/oracle/admin/diag/rdbms/hrprd89/HRPRD89/incident/incdir_42193/HRPRD89_j000_5021728_i42193.trc

What follows after that is another entry....
So the number of lines before or after is variable...

Last edited by Scrutinizer; 06-28-2012 at 12:16 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 14  
Old 06-28-2012
Debian

got thanks for the help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Insert text after the first occurance of searched string entry in a file

My server xml file has huge data part of which i'm sharing below. I wish to add the below text held by variable "addthisline" after the closing braces i.e --> once the first </Connector> tag is found. addthisline="I need to be inserted after the comments" Thus my searchstring is... (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies

3. Shell Programming and Scripting

awk to skip lines find text and add text based on number

I am trying to use awk skip each line with a ## or # and check each line after for STB= and if that value in greater than or = to 0.8, then at the end of line the text "STRAND BIAS" is written in else "GOOD". So in the file of 4 entries attached. awk tried: awk NR > "##"' "#" -F"STB="... (6 Replies)
Discussion started by: cmccabe
6 Replies

4. Shell Programming and Scripting

Search String and extract few lines under the searched string

Need Assistance in shell programming... I have a huge file which has multiple stations and i wanted to search particular station and extract few lines from it and the rest is not needed Bold letters are the stations . The whole file has multiple stations . Below example i wanted to search... (4 Replies)
Discussion started by: ajayram_arya
4 Replies

5. Shell Programming and Scripting

Read n lines from a text files getting n from within the text file

I dont even have a sample script cause I dont know where to start from. My data lookes like this > sat#16 #data: 15 site:UNZA baseline: 205.9151 0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722 0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
Discussion started by: malandisa
8 Replies

6. Shell Programming and Scripting

sed show lines text between 2 blank lines

I have a file like blah blah blah blah this is the text I need, which might be between 1-4 lines, but always has a blank line above and below it, and is at the end of the text file the code tags don't show the trailing blank line. I started by deleting the last blank line with: ... (2 Replies)
Discussion started by: unclecameron
2 Replies

7. Shell Programming and Scripting

Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like: <ROW> some information more information </ROW> I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies

8. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

9. Shell Programming and Scripting

how to get lines prior to the line being searched

Hi, Can anbody please let me know how i can retrieve lines above the line being searched in a file. I am looking for an error message from a file, if I see that message I want the lines above that message along with this line. how do we do this. Please do let me know An example which i have... (2 Replies)
Discussion started by: arunrao_oradba
2 Replies

10. Shell Programming and Scripting

How to delete first 5 lines and last five lines in all text files

Hi I want to delete first five and last five lines in text files without opening the file and also i want to keep the same file name for all the files. Thanks in advance!!! Ragav (10 Replies)
Discussion started by: ragavendran31
10 Replies
Login or Register to Ask a Question