ログファイルが存在し、一連の行末でブロックが関連していることを確認できます。これで、「Content-Length:0」で終わり、その行の前の最後の「--」で始まるブロックを削除するsedなどのコマンドを探しています。
試しましたが、 sed -n "/--/,/Content-Length: 0/d"
最初の「--」と最初の「Content-Length:0」をインポートして削除しました。
前任者:
line 1 "--"
line 2
line 3 "Content-Length: 20"
line 4 "--"
line 5
line 6 "Content-Length: 0"
1~6行ではなく4,5,6行を削除したいです。
どうすればいいですか?
答えは、作業を完了するのでtac
はなく、使用することです!しかし、最終的には建築に使用したいcat
です。tail -f
ベストアンサー1
以下は、使用される1つの方法ですGNU sed
。
sed -n '/--/,/Content-Length: 0/ { H; /Content-Length: 0/ { g; s/\n\(.*\)\n.*--.*/\1/p } }'
結果:
line 1 "--"
line 2
line 3 "Content-Length: 20"
説明する:
Match between the pattern range. Append this range to the hold space. On the last
line of the range, copy the hold space to pattern space to work with it. Then use
find/replace regex to remove everything after the last occurrence of '--'. HTH.