我正在运行一个名为stm的程序.我想只保存文本文件中包含文本"ERROR"的那些stderr消息.我也想要控制台上的消息.
我怎么用bash做到这一点?
nos*_*sid 14
如果ERROR控制台(stderr)上只显示包含的消息,请使用以下管道:
stm |& grep ERROR | tee -a /path/to/logfile
Run Code Online (Sandbox Code Playgroud)
如果所有消息都应显示在控制台(stderr)上,请使用以下命令:
stm |& tee /dev/stderr | grep ERROR >> /path/to/logfile
Run Code Online (Sandbox Code Playgroud)
编辑:没有连接标准输出和标准错误的版本:
stm 2> >( grep --line-buffered ERROR | tee -a /path/to/logfile >&2 )
stm 2> >( tee /dev/stderr | grep --line-buffered ERROR >> /path/to/logfile )
Run Code Online (Sandbox Code Playgroud)