Selecting line ahead and next using AWK or SED


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Selecting line ahead and next using AWK or SED
# 1  
Old 12-10-2008
Data Selecting line ahead and next using AWK or SED

Smilie
Good Day,

I have this script that gets the archive names and the time it applies based on the alert log. The application of archives are of daily basis and usually many so having this script helps my job become easier.

My problem is that when i get all the time stamps and archive names, it also gets the creation time stamp of the datafile which shouldnt have been included.
like the logs example below:

Wed Dec 10 13:18:26 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8600.dbf
Wed Dec 10 13:19:19 2008
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Wed Dec 10 13:19:19 2008
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Dec 10 13:19:19 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8601.dbf
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Wed Dec 10 13:19:30 2008
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Dec 10 13:19:30 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8602.dbf
Wed Dec 10 13:19:44 2008
Recovery created file /oracle/P03/sapdata7/p03_252/p03.data252
Successfully added datafile 281 to media recovery
Datafile #281: '/oracle/P03/sapdata7/p03_252/p03.data252'
Wed Dec 10 13:20:00 2008
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Wed Dec 10 13:20:01 2008
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Dec 10 13:20:01 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8603.dbf
Wed Dec 10 13:20:27 2008
ORA-279 signalled during: ALTER DATABASE RECOVER CONTINUE DEFAULT ...
Wed Dec 10 13:20:27 2008
ALTER DATABASE RECOVER CONTINUE DEFAULT
Wed Dec 10 13:20:27 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8604.dbf
Wed Dec 10 13:20:38 2008



I just want to get the time stamp of the archive which is not fixed. what AWK or SED command do i use to get the line leading and succeeding of my archive specified.



Wed Dec 10 13:19:30 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8602.dbf
Wed Dec 10 13:19:44 2008
Media Recovery Log /oracle/P03/oraarch/P03arch1_8603.dbf
Wed Dec 10 13:19:44 2008
# 2  
Old 12-10-2008
try this!!! Smilie
Code:
awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=1 a=0 s="Media Recovery" filename

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

selecting specific fields in a file (maybe with sed?)

Hi, I have a file with following lines: chr1 10 AC=2;AF=1.00;AN=2;DP=2;Dels=0.00;HRun=0;HaplotypeScore=0.00;MQ=23.00;MQ0=0;QD=14.33;SB=-10.01 chrX 18 AB=0.52;AC=1;AF=0.50;AN=2;DP=203;DS;Dels=0.00;HRun=0;HaplotypeScore=20.01;MQ=15.63;MQ0=85;QD=12.80;SB=-1289.58 I need to extract 4... (2 Replies)
Discussion started by: menenuh
2 Replies

4. Shell Programming and Scripting

Selecting specific 'id's from lines and columns using 'SED' or 'AWK'

Hello experts, I am new to this group and to 'SED' and 'AWK'. I have data (text file) with 5 columns (C_1-5) and 100s of lines (only 10 lines are shown below as an example). I have to find or select only the id numbers (C-1) of specific lines with '90' in the same line (of C_3) AND with '20' in... (6 Replies)
Discussion started by: kamskamu
6 Replies

5. Shell Programming and Scripting

Selecting a part of the text (regex pattern, awk, sed)

Hello, let's start by giving you guys a few examples of the text: "READ /TEXT123/ABC123" "READ /TEXT123/ABC123/" "READ TEXT123/ABC123" "READ TEXT123/ABC123/" "READ TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123/" TEXT and ABC can be and I... (5 Replies)
Discussion started by: TehOne
5 Replies

6. UNIX for Dummies Questions & Answers

Selecting specific line using awk

Hi, I would like to get the specific line from the file taking specific coloumn as reference. Thanks and Regards (1 Reply)
Discussion started by: kkarthik_kaja
1 Replies

7. Shell Programming and Scripting

Selecting lines with sed

Hi all, I have a file with special characters like this file1 691775025 ýÄqJ8^Z^Y{ 2004-08-23E P 100.00 45585025 0527541139295037342008-07-25OEP 100.00 6983025 ýB<9D>x<^F^Xb 2004-11-16SPP 100.00 I need a sed command to print the lines which don't have special characters.ie., only line 2... (9 Replies)
Discussion started by: allinshell
9 Replies

8. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

9. Shell Programming and Scripting

Read logline line by line with awk/sed

Hello, I have a logfile which is in this format: 1211667249500#3265 1211667266687#2875 1211667270781#1828 Is there a way to read the logfile line by line every time I execute the code and put the two numbers in the line in two separate variables? Something like: 1211667249500#3265... (7 Replies)
Discussion started by: dejavu88
7 Replies

10. Shell Programming and Scripting

Selecting a line value

Hello, I just wanted to know if there is a way in UNIX to select a line value from a list of words. there is no line number before each word, hence could not use grep. (4 Replies)
Discussion started by: unibboy
4 Replies
Login or Register to Ask a Question