您如何通过 grep 将输入通过管道传输到另一个实用程序? [英] How do you pipe input through grep to another utility?

查看:21
本文介绍了您如何通过 grep 将输入通过管道传输到另一个实用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tail -f"来跟踪更新的日志文件;接下来我将其输出通过管道传递给 grep 以仅显示包含搜索词的行(在本例中为org.springframework");最后我想做的是将 grep 的输出通过管道传输到第三个命令cut":

I am using 'tail -f' to follow a log file as it's updated; next I pipe the output of that to grep to show only the lines containing a search term ("org.springframework" in this case); finally I'd like to make is piping the output from grep to a third command, 'cut':

tail -f logfile | grep org.springframework | cut -c 25-

cut 命令会为我删除每行的前 25 个字符如果它可以从 grep 获取输入!(如果我从链中消除了grep",它会按预期工作.)

The cut command would remove the first 25 characters of each line for me if it could get the input from grep! (It works as expected if I eliminate 'grep' from the chain.)

我在 bash 中使用 cygwin.

I'm using cygwin with bash.

实际结果:当我添加第二个管道以连接到cut"命令时,结果是它挂起,好像在等待输入(以防万一).

Actual results: When I add the second pipe to connect to the 'cut' command, the result is that it hangs, as if it's waiting for input (in case you were wondering).

推荐答案

在我的系统上,在我得到任何输出之前缓冲了大约 8K.此序列可以立即跟踪文件:

On my system, about 8K was buffered before I got any output. This sequence worked to follow the file immediately:

tail -f logfile | while read line ; do echo "$line"| grep 'org.springframework'|cut -c 25- ; done

这篇关于您如何通过 grep 将输入通过管道传输到另一个实用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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