2010-09-29 109 views
0

考慮這個例子鏈:檢查標準輸出

cat foo.txt | grep -v foo | grep -v bar | grep -v baz 

我想檢查標準輸出所述第二grep的以及所得到的標準輸出的內容:

cat foo.txt | grep -v foo | grep -v bar | UNKNOWN | grep -v baz 

所以我需要一個工具,UNKNOWN,例如將stdout的內容轉儲到一個文件中,並沿着鏈傳遞stdout。

是否存在工具UNKNOWN(Windows和Linux的答案都是相關的)?

回答

1

我認爲有一件事叫做'tee'就是給你的。

反映來自Bob的評論的更新: cat foo.txt | grep -v foo | grep -v bar | tee -a inspection.txt | grep -v baz

+2

cat foo.txt | grep -v foo | grep -v bar | tee -a inspection.txt | grep -v baz – 2010-09-30 05:39:44

0

無法給它一個鏡頭,但像Gabriel和Bob指出的那樣,命令$ tee (man tee)可以幫助你。 tee命令將接受輸入並將其回顯到stdout以及文件。正如鮑勃在他的評論中說:

cat foo.txt | grep -v foo | grep -v bar | tee -a inspection.txt | grep -v baz 

會從grep -v bar輸出,並把它輸出到標準輸出,以及inspection.txt。 -a標誌導致它附加到檢查而不是創建一個全新的文件。