跟隨檔案尾部時,egrep 重定向不起作用

跟隨檔案尾部時,egrep 重定向不起作用

我想重定向 tail -f 的過濾輸出,如下所示:

tail -f myfile | egrep '(searchterm_a)|(searchterm_b)' >> outputfile.txt

但由於某種原因,重定向並沒有像我預期的那樣運作。相反,會建立一個空文件。

有誰知道我在哪裡犯了錯?

答案1

可能是緩衝問題(參見例如一個非常相似的問題)。你可以嘗試例如:

tail -f myfile | egrep --line-buffered '(searchterm_a)|(searchterm_b)' >> outputfile.txt

相關內容