How to cut specific line and one line under?

Hi guys,

I need to analyze the following alert log file:

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:

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

If awk is allowed:

awk '/^Beginning log/{print;getline;print}' logfile
$> 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

Thanks for both of you!
Franklin52 - your command runs perfectly!
zaxxon - I got the following error when I ran your suggestion:

{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

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

Hi expert,

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

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

Regards,
Nir

 
[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
 

GNU grep will work for the given requirement as:

grep -n "Beginning log switch checkpoint up to RBA" -A1 t
1:Beginning log switch checkpoint up to RBA [0x4243f.2.10], SCN: 3916025539605
2-Sat May  1 00:54:52 2010
--
9:Beginning log switch checkpoint up to RBA [0x42440.2.10], SCN: 3916026109591
10-Sat May  1 00:57:40 2010