如何使用GREP匹配但不打印比赛?

发布于 2025-02-13 03:45:21 字数 328 浏览 2 评论 0原文

我是Linux Shell的新手,并且正在尝试使用以下条件进行此操作,最好是在一行中:它无法向终端输出任何内容。

/var/folder/program.exe -L parameters | grep text_to_filter && echo SomeText >'/tmp/Log.txt'

问题是.exe将XML数据吐出到终端。我无法弄清楚如何进行grep,使用退出状态,但没有对每场比赛的输出的屏幕混乱。如果我使用/dev/null 2>& 1,它将其管道非常好,但是我无法掌握数据。有什么想法吗?

I'm new to linux shell and am trying to do this, preferably in one line, with the following condition: It can't output anything to the terminal.

/var/folder/program.exe -L parameters | grep text_to_filter && echo SomeText >'/tmp/Log.txt'

The problem is the .exe spits out XML data to terminal. I can't figure out how to grep, use the exit status, but not have the screen cluttered with the output of each match. If I use /dev/null 2>&1, it pipes it quite but then I can't grep the data. Any idea's?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自找没趣 2025-02-20 03:45:21

使用GREP -Q(QUIET)

/var/folder/program.exe -L parameters |
grep -q "text_to_filter" && echo 'SomeText' > '/tmp/Log.txt'

按照man grep

-q, - quiet, - silent
安静的;不要将任何内容写入标准输出。如果发现任何匹配,则立即以零状态退出,即使错误
被检测到。也看
-s或-no -messages选项。

Use grep -q (quiet)

/var/folder/program.exe -L parameters |
grep -q "text_to_filter" && echo 'SomeText' > '/tmp/Log.txt'

As per man grep:

-q, --quiet, --silent
Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error
was detected. Also see
the -s or --no-messages option.

看轻我的陪伴 2025-02-20 03:45:21

尝试使用|&而不是只是|。 (需要bash 4)

Try using |& rather than just |. (needs bash 4)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文