event
time:00.00
event no.:01
Type:A
result:success
event
time:00.01
event no.:02
result:success
event
time:00.02
event no.:03
Type:B
result:fail
我有上面的文件,我想以表格格式写这个文件,如下所示: 时间|事件编号|类型|结果|
00.00|01|A|success|
00.01|02||success|
00.02|03|B|fail|
如何使用linux shell脚本执行此操作?
答案 0 :(得分:0)
你可以使用这个awk:
awk -F' *: *' 'NF>1{a[$1]=$2; next}
/^event/ && NR>5{print a["time"], a["event no."], a["Type"], a["result"] OFS;delete a;next}
END{print a["time"], a["event no."], a["Type"], a["result"] OFS}' OFS='|' file
00.00|01|A|success|
00.01|02||success|
00.02|03|B|fail|