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

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

问题描述

我的脚本由于缺少某些文件而失败.

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

运行脚本并将其通过管道传送到 grep

Running the script and piping it to grep

$ ./adder | grep Error

产生以下输出:

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

和不同文件的类似输出

我想从这个输出中提取像 v2.2_V3_194424_194712/output_853.root 这样的根文件,但是做 ./adder |grep 错误 |grep .root 不起作用.

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.

这是为什么?

推荐答案

就像 piokuc 建议的那样,将 stderr 与 stdout 结合起来.但是,我认为您正在寻找更好的 grep 调用:

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天全站免登陆