使用 tee 和 grep 将输出通过管道传输到文件中,但看到的是完整输出

Pipe output with tee & grep into file but seeing full output

尝试将 grep 的输出写入文件,同时在终端中使用 by grep 不受影响的输出。

示例:

命令:

cat file | grep 'aaa' >> any.txt #Missing parameters here

终端中的期望输出:

aaa
bbb
ccc

重定向到 any.txt

aaa

那么可能不是grep,你可以用awk代替:

cat file | awk '/aaa/{print >>"output.txt";}1'