简体   繁体   English

表格式外壳脚本

[英]Table Format Shell Script

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

I have the above file and I want to write this file in table format like this: time|event no.|Type|result| 我有上面的文件,并且想要以这种表格格式写入此文件:time | event no。| Type | result |

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

How to do this using linux shell scripting? 如何使用Linux Shell脚本执行此操作?

You can use this awk: 您可以使用以下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|

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM