ログファイルから特定の行を選択してテキストファイルに保存する必要があります。次の方法を試しましたが、どちらも期待どおりに機能しません。 "todel.txt"ファイルは0バイトを表示します。
tail -f general.log | grep Some_word > >(tee -a todel.txt)
tail -f general.log | grep Some_word ; tee todel.txt
tail -f general.log | grep Some_word | tee -a todel.txt
ベストアンサー1
stdbuf(1)
パイプラインに以下を追加する必要があります。
tail -f general.log | stdbuf -oL grep Some_word | tee -a todel.txt
これは、grep
stdoutストリームバッファリングモードをラインバッファリングに設定します。それ以外の場合は、grep
ストリームから少なくとも4096バイトを取得するのを待ちます(これはLinuxでバッファリングされたI / Oのデフォルトです)。
または次にgrep
電話することができます--line-buffered
。
tail -f general.log | grep --line-buffered Some_word | tee -a todel.txt
バラよりパイプラインでバッファリングをオフにするそしてhttp://www.pixelbeat.org/programming/stdio_buffering/詳細な説明のために。