过滤脚本输出到一个文件,一个完整的输出到另一个文件

Filter output of script to a file, an the full output to another file

我有一个脚本,每 30 分钟从 api 获取日志,我想过滤脚本的输出并将过滤后的数据存储到一个文件中,并将完整数据存储到另一个文件中. 我试过了,但我得到一个空文件

script.py | tee >> ( grep 'MAAS' > filtered_$date.log  ) fulldata_$date.log

这个怎么样?

script.py | tee "fulldata_$date.log" | grep 'MAAS' > "filtered_$date.log"

首先 tee 未过滤的数据,grep 仍然可以看到所有内容并进行过滤。

你可以用进程替换来反转它,比如

script.py | tee >(grep 'MAAS' > "filtered_$date.log") > "fulldata_$date.log"

但这感觉既不简单也不易于阅读。