Grep变成变量并保持stdout? [英] Grep into variable and maintain stdout?

查看:66
本文介绍了Grep变成变量并保持stdout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的流程很长,我想从大量的输出中捕获一小部分数据.

I've got a long running process and I want to capture a tiny bit of data from the big swath of output.

我可以通过grep传递它来执行此操作,但是然后我看不到它会喷出所有其他信息.

I can do this by piping it through grep, but then I can't watch it spew out all the other info.

我基本上希望grep将找到的内容保存到变量中,而不要将stdout保留下来.我该怎么办?

I basically want grep to save what it finds into a variable and leave stdout alone. How can I do that?

推荐答案

使用过程替换 I/O重定向:

{ var=$(cmd | tee >(grep regexp) >&3); } 3>&1

这篇关于Grep变成变量并保持stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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