2014-02-10 53 views
0
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 

我有上述文件,我想寫在這樣的表格式文件: 時間|事件沒有|類型|結果|表格式Shell腳本

00.00|01|A|success| 
00.01|02||success| 
00.02|03|B|fail| 

如何使用Linux shell腳本執行此操作?

+1

確定,所以,你的腳本的一部分是不明確?你的代碼在哪裏? –

回答

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|