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...
上記のデータに基づいて、段落ごとに3つの列を作成し、行を別の/新しいファイルに保存しようとしています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