How to cut specific line and one line under?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to cut specific line and one line under?
# 1  
Old 05-20-2010
How to cut specific line and one line under?

Hi guys,

I need to analyze the following alert log file:
Code:
Beginning log switch checkpoint up to RBA [0x4243f.2.10], SCN: 3916025539605
Sat May  1 00:54:52 2010
Thread 1 advanced to log sequence 271423 (LGWR switch)
  Current log# 1 seq# 271423 mem# 0: /dw/stg_redo01/log_dwstg_g1_m1.log
  Current log# 1 seq# 271423 mem# 1: /dw/stg_redo02/log_dwstg_g1_m2.log
Sat May  1 00:54:56 2010
Completed checkpoint up to RBA [0x4243f.2.10], SCN: 3916025539605
Sat May  1 00:57:40 2010
Beginning log switch checkpoint up to RBA [0x42440.2.10], SCN: 3916026109591
Sat May  1 00:57:40 2010
Thread 1 advanced to log sequence 271424 (LGWR switch)
  Current log# 4 seq# 271424 mem# 0: /dw/stg_redo01/log_dwstg_g4_m1.log
  Current log# 4 seq# 271424 mem# 1: /dw/stg_redo02/log_dwstg_g4_m2.log
Sat May  1 00:57:52 2010
Completed checkpoint up to RBA [0x42440.2.10], SCN: 3916026109591

From this file I need to cut the lines that beginning with "Beginning log switch checkpoint up to RBA" and every line under this line which reflect the time stamp.
The final file should be as the following:
Code:
Beginning log switch checkpoint up to RBA [0x42428.2.10], SCN: 3916022809348
Sat May  1 00:00:29 2010
Beginning log switch checkpoint up to RBA [0x42429.2.10], SCN: 3916022929579
Sat May  1 00:02:52 2010
Beginning log switch checkpoint up to RBA [0x4242a.2.10], SCN: 3916022993393
Sat May  1 00:04:12 2010
...

How to do it with sed command?

Thanks in advance,
Nir
# 2  
Old 05-20-2010
If awk is allowed:
Code:
awk '/^Beginning log/{print;getline;print}' logfile

# 3  
Old 05-20-2010
Code:
$> sed '/Beginning log switch checkpoint up to RBA/!d;n;!d' infile
Beginning log switch checkpoint up to RBA [0x4243f.2.10], SCN: 3916025539605
Sat May  1 00:54:52 2010
Beginning log switch checkpoint up to RBA [0x42440.2.10], SCN: 3916026109591
Sat May  1 00:57:40 2010

# 4  
Old 05-20-2010
Thanks for both of you!
Franklin52 - your command runs perfectly!
zaxxon - I got the following error when I ran your suggestion:
Code:
{oracle} /app01/oracle/admin/dwprod/bdump C3PO-PROD> sed '/Beginning log switch checkpoint up to RBA/!d;n;!d' alert_dwprod.log
d: Event not found.

Best regards,
Nir
# 5  
Old 05-20-2010
try using the grep like

grep -n "Beginning log switch checkpoint up to RBA" -A1 <file name>


use -n option to show the line number

Last edited by expert; 05-20-2010 at 10:53 AM.. Reason: to include the option to show line number
# 6  
Old 05-20-2010
Hi expert,

This command does only half of the work Smilie
I need also the line under.

Thanks any way.
Franklin52 has already given me a good solution with the AWK command.

Regards,
Nir
# 7  
Old 05-20-2010
Quote:
Originally Posted by nir_s
Thanks for both of you!
Franklin52 - your command runs perfectly!
zaxxon - I got the following error when I ran your suggestion:
Code:
{oracle} /app01/oracle/admin/dwprod/bdump C3PO-PROD> sed '/Beginning log switch checkpoint up to RBA/!d;n;!d' alert_dwprod.log
d: Event not found.

Best regards,
Nir
Code:
 
[ygemici\unix\is\not\linux~]\YG sed -n '/Beginning/ {N;p;}' file
Beginning log switch checkpoint up to RBA [0x4243f.2.10], SCN: 3916025539605
Sat May  1 00:54:52 2010
Beginning log switch checkpoint up to RBA [0x42440.2.10], SCN: 3916026109591
Sat May  1 00:57:40 2010

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to cut a specific pattern from a line

Hello, I need to cut a specific pattern from a line irrespecitve of knowing field place. I am aware to cut field if you know the place of the field, but for me The sting place varies. 1468129514436,0,something_error,Non HTTP response code: java.net.URISyntaxException,Non HTTP response... (5 Replies)
Discussion started by: mirwasim
5 Replies

2. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Cut from specific line number to a line number

Hi All, I've a file like this.. Sheet1 a,1 a,2 a,3 a,4 a,5 Sheet2 a,6 a,7 a,8 a,9 a,10 Sheet3 a,11 a,12 a,13 (7 Replies)
Discussion started by: manab86
7 Replies

4. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

5. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

6. Shell Programming and Scripting

Using awk to read a specific line and a specific field on that line.

Say the input was as follows: Brat 20 x 1000 32rf Pour 15 p 1621 05pr Dart 10 z 1111 22xx My program prompts for an input, what I want is to use the input to locate a specific field. Like if I type in, "Pou" then it would return "Pour" and just "Pour" I currently have this line but it is... (6 Replies)
Discussion started by: Bungkai
6 Replies

7. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

8. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

9. Shell Programming and Scripting

To cut a specific line

Hi, I need to remove a specific line from a file.. For eg: From the html codings, I need to find the word "iframe frameborder" and cut it . I tried with find . -type f -exec grep -H 'iframe frameborder' {} \; > <filename> From the output of this result, I need to remove the "iframe... (14 Replies)
Discussion started by: gsiva
14 Replies

10. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies
Login or Register to Ask a Question