我有一个文件input.txt
,其中包含以下几个段落:
[730480.910190] [MACSTATUSIND] ACTIND_ParseMACSTATUS:
[730480.910205] fe 0a 39 01 0a 00 51 e7 ba 9d c7 0d 00 00 00 00 ..9...Q....
[730480.910220] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...........
[730480.910233] 00 00 00 00 00 00 00 00 00 00 xx xx xx xx xx xx .....:bC.B.
[730480.910247] xx xx yy yy yy yy yy yy zz zz 64 34 e8 ff 00 00 ......d4...
[730480.910190] [MACSTATUSIND] ACTIND_ParseMACSTATUS:
[730480.910205] fe 0a 39 01 0a 00 51 e7 ba 9d c7 0d 00 00 00 00 ..9...Q....
[730480.910220] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...........
[730480.910233] 00 00 00 00 00 00 00 00 00 00 aa bb cc dd ee ff .....:bC.B.
[730480.910247] gg hh ii jj kk ll mm nn oo pp 64 34 e8 ff 00 00 ......d4...
根据上面的数据,对于每个段落,我想制作三列,然后将这些行存储在不同的/新文件中new.txt
。
输出:new.txt
col1 col2 col3
------- ---- ------
xxxxxxxx | yyyyyy | zzzz
aabb..gghh | ii..nn | oopp
笔记:上述段落日志在文件中重复多次。所有段落都应具有以[MACSTATUSIND] ACTIND_ParseMACSTATUS:
答案1
awk 'BEGIN { print " col1 | col2 | col3" }
/^\[730480.910233\] / {SA = $12 $13 $14 $15 $16 $17}
/^\[730480.910247\] / { print SA $2 $3 " | " $4 $5 $6 $7 $8 $9 " | " $10 $11}
' input.txt > new.txt