用grep管道错误信息 [英] Piping error messages with grep

查看:166
本文介绍了用grep管道错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



运行脚本并将其管理为grep

  $ ./adder | grep Error 

产生以下输出:

<$ < TFile :: ReadBuffer>中的错误:读取来自文件v2.2_V3_194424_194712 / output_853.root的所有请求字节的错误,得到0 $ 300
< TFile :: Init> ;: v2.2_V3_194424_194712 / output_853.root不是ROOT文件

以及不同文件的类似输出



我想从此输出中提取根文件,例如 v2.2_V3_194424_194712 / output_853.root ,但
在做 ./加法器| grep错误| grep .root 不起作用。



这是为什么?

解决方案

像piokuc的建议,结合stderr和stdout。不过,我认为你正在寻找更好的grep调用:

  ./加法器2>& 1 | grep^ Error| grep -oP'[^] * \.root'


I have a script that fails because some files are missing.

Running the script and piping it to grep

$ ./adder | grep Error

produces the following output:

Error in <TFile::ReadBuffer>: error reading all requested bytes from file v2.2_V3_194424_194712/output_853.root, got 0 of 300
Error in <TFile::Init>: v2.2_V3_194424_194712/output_853.root not a ROOT file

and similar output with different files

I'd like to extract the root files like v2.2_V3_194424_194712/output_853.root from this output, but doing ./adder | grep Error | grep .root doesn't work.

Why is that?

解决方案

Like piokuc's suggests, combine stderr with stdout. However, I think you are looking a better invocation of grep:

./adder 2>&1 | grep "^Error" | grep -oP '[^ ]*\.root'

这篇关于用grep管道错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆