shell命令如何实现文件数据提取处理?(请高手指点)
有如下一文件:
------------------------------------------------------
2011/10/14 20:10:00 ** error **
Method: run_batchtools_command([start],[batch_name = "Bancassurance_Load_M",command = [start])
TE Date: 2011/10/14
LA Date: 2011/10/14
0
Message gtsystem : obj . 11053
:$gtbatch:c_batch_descriptor$1nn.run_batchtools_command([start],[batch_name = "Bancassurance_Load_M",command = [start])
Self: $gtbatch:c_batch_descriptor$1nn
Method: cmd_force_start([batch_name = "Bancassurance_Load_M",command = [start])
TE Date: 2011/10/14
LA Date: 2011/10/14
0
Message gtsystem : obj . 11053
Exit with code 71
ensure_loaded_boot_roots
undefined predicate
------------------------------------------------------
2011/10/14 20:15:00 ** error **
Method: run_batchtools_command([start],[batch_name = "Batch_Issue_M",command = [start])
TE Date: 2011/10/14
LA Date: 2011/10/14
0
Message gtsystem : obj . 11053
:$gtbatch:c_batch_descriptor$1nn.run_batchtools_command([start],[batch_name = "Batch_Issue_M",command = [start])
Self: $gtbatch:c_batch_descriptor$1nn
Method: cmd_force_start([batch_name = "Batch_Issue_M",command = [start])
TE Date: 2011/10/14
LA Date: 2011/10/14
0
Message gtsystem : obj . 11053
Exit with code 77
ensure_loaded_boot_roots
undefined predicate
------------------------------------------------------
这样类似的多段内容,现在要提取出batch_name和Exit with code,大致格式如下:
Bancassurance_Load_M Exit with code 71 2011/10/14 20:10:00
Batch_Issue_M Exit with code 77 2011/10/14 20:15:00
(这个时间是最开始error行的时间)
batch_name要与Exit with code和时间相互匹配,每2个“---------”之间的数据为一段,他们是一起的,现在用shell要如何实现呢?之前一次提问没加后面的时间,一哥们给的可用答案是:
cat 1.txt|gawk 'BEGIN{FS="="} {
if($0~/batch_name = "/) {if(gsub(/"/,"")) split($2,t1,",");v1=t1[1]};
if($0~/Exit with code/) {v2=$0;print v1" "v2};
}'
现在要加个error的时间,还请给指点下,谢谢!
cat 1.txt | gawk '{
if(match($0, /^(.+) \*\谈郑闭* error \*\*/, va)) {
errtime=va[1]
} else if(match($0, /batch_name = \"(.+)\"/, va)) {
batchmode=va[1]
} else if(match($0, /^Exit with code (.+)$/含裂, va)) {
print errtime "丛漏 " batchmode " exit with code " va[1]
} else
next
}'
cat 1.txt | gawk '
/.*error \\*\\*/ {date = gensub("^(.*) \\*\\* error \\*\\*", "宴慧\\1", "g")}
/^.*batch_name = .*/ {name = gensub("^.*batch_name = \"([^\"]*).*", "\\1", "g")}
/^Exit with code .*/ {printf "晌世答返尺%s %s %s\n", name, $0, date}'