bash命令与grep在stderr上的东西,并将结果保存在文件中 [英] bash command to grep something on stderr and save the result in a file
本文介绍了bash命令与grep在stderr上的东西,并将结果保存在文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行一个称为STM程序。我只想保存那些包含在一个文本文件中的文本ERROR标准错误消息。我也想在控制台上的消息。
I am running a program called stm. I want to save only those stderr messages that contain the text "ERROR" in a text file. I also want the messages on the console.
我如何做,在bash?
How do I do that in bash?
推荐答案
如果只包含的信息使用下列管道错误
应显示在控制台(标准错误)上:
Use the following pipeline if only messages containing ERROR
should be displayed on the console (stderr):
stm |& grep ERROR | tee -a /path/to/logfile
使用下面的命令,如果所有消息应在控制台(标准错误)上显示:
Use the following command if all messages should be displayed on the console (stderr):
stm |& tee /dev/stderr | grep ERROR >> /path/to/logfile
编辑:版本,无需连接标准输出和标准错误:
Versions without connecting standard output and standard error:
stm 2> >( grep --line-buffered ERROR | tee -a /path/to/logfile >&2 )
stm 2> >( tee /dev/stderr | grep --line-buffered ERROR >> /path/to/logfile )
这篇关于bash命令与grep在stderr上的东西,并将结果保存在文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文