【发布时间】:2016-03-21 08:41:29
【问题描述】:
我知道如何通过管道输出标准输出:
./myScript | grep 'important'
上述命令的示例输出:
Very important output.
Only important stuff here.
但是在greping 的同时,我还想在每一行添加 echo 一些东西,所以它看起来像这样:
1) Very important output.
2) Only important stuff here.
我该怎么做?
编辑:显然,我没有足够清楚地指定我想要做什么。行数只是一个例子,我一般想知道如何将文本(任何文本,包括变量和诸如此类)添加到管道输出。我看到使用awk '{print $0}' 可以实现这一目标,其中$0 是我正在寻找的解决方案。
还有其他方法可以实现吗?
【问题讨论】:
-
这与编程无关,但请尝试
grep -n 'important'。 -
我在这里做读心术。对于消息,您最好使用
stderr来通知脚本的进度。这不会干扰您正在使用的stdout。