有一个Oracle RMAN生成的日志文件,我想将其与sed一起传递并去除肯定的验证结果。
原始日志文件可以在这里查看: https://pastebin.com/XhEEs9e9
This log file consists of many sections like this:
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
我要实现的目标是sed去除所有损坏的块和失败的块均为“ 0”的块。
为此,我制定了一个相当长的sed命令,如下所示:
/tmp/rman.log | /usr/gnu/bin/sed -E '/^File[[:space:]]*Status[[:space:]]*Marked[[:space:]]*Corrupt[[:space:]]*Empty[[:space:]]*Blocks[[:space:]]*Blocks[[:space:]]*Examined[[:space:]]*High SCN$/{N;N;/\n[[:digit:]]*[[:space:]]*OK[[:space:]]*[[:digit:]]*[[:space:]]*[[:digit:]]*[[:space:]]*[[:digit:]]*[[:space:]]*[[:digit:]]*$/{N;N;N;N;/\n[[:space:]]*Data[[:space:]]*0[[:space:]]*[[:digit:]]*[[:space:]]*$/{N;/\n[[:space:]]*Index[[:space:]]*0[[:space:]]*[[:digit:]]*[[:space:]]*$/{N;/\n[[:space:]]*Other[[:space:]]*0[[:space:]]*[[:digit:]]*[[:space:]]*$/d}}}}'
该命令似乎可以正常工作,某些块已从原始日志文件中删除,但其中一些块被保留了。
问题是,我不知道为什么...:(
过滤后的日志可以在这里看到: https://pastebin.com/rKgfj28B
我的命令中缺少某些内容吗?遗留的块也为损坏的块和失败的块提供“ 0”,但是以某种方式它们根本不匹配。
答案 0 :(得分:1)
如果问题中以File
开头的文本块是“块”,并且每个块之间都有空白行,例如:
$ cat file
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 3 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 1 232975
Other 0 716411
这就是您所需要的:
$ awk -v RS= -v ORS='\n\n' '($19 $36 $39 $42)+0' file
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 3 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 1 232975
Other 0 716411
否则,如果块之间没有空行,那么这就是您所需要的:
$ cat tst.awk
/^File/ { if (NR>1) prt() }
{ rec = rec $0 ORS }
END { prt() }
function prt( f) {
split(rec,f)
if ( (f[19] f[36] f[39] f[42])+0 ) {
printf "%s", rec
}
rec = ""
}
例如:
$ cat file
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 3 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 1 232975
Other 0 716411
。
$ cat tst.awk
/^File/ { if (NR>1) prt() }
{ rec = rec $0 ORS }
END { prt() }
function prt( f) {
split(rec,f)
if ( (f[19] f[36] f[39] f[42])+0 ) {
printf "%s", rec
}
rec = ""
}
。
$ awk -f tst.awk file
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 3 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 0 232975
Other 0 716411
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
58 OK 0 7964 1280000 8964120502
File Name: /oracle/PRD/sapdata3/sr3_55/sr3.data55
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 322650
Index 1 232975
Other 0 716411