Bash:行長制限のあるファイルへのログ記録中にエラーが発生しました。

Bash:行長制限のあるファイルへのログ記録中にエラーが発生しました。

現在、このコマンドを使用して./myprogram 2> error.logプログラムエラーを特定のファイルに記録しています。ただし、一部の行は長すぎるため、読み続けるにはスクロールする必要があります。エラーログに行の長さ制限(たとえば、1行あたり80文字)を設定したいと思います。この制限を超える行は、次の行に続く。

オリジナルコンテンツ:

This line is not over 80 characters.
This line is over 80 characters thus will be cut at the 80th character, and will continue onto the next line.

エラーログ(最終結果):

This line is not over 80 characters.
This line is over 80 characters thus will be cut at the 80th character, and will
 continue onto the next line.

ベストアンサー1

プログラム出力をパイプしてfold80文字の幅で出力をラップし、ファイルにリダイレクトできます。

./myprogram 2>&1 >/dev/null | fold -w 80 > error.log

上記はstderrの保存にのみ興味があると仮定しています。

おすすめ記事