你怎么管输入通过grep的另一个效用? [英] How do you pipe input through grep to another utility?

查看:127
本文介绍了你怎么管输入通过grep的另一个效用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的'尾巴-f遵​​循一个日志文件,因为它的更新;下一个I管,输出到grep只显示包含搜索术语(在这种情况下org.springframework)的线路;最后我想提出的是从管道grep的输出到第三个命令,'一刀切':

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.)

我使用cygwin的使用bash。

I'm using cygwin with bash.

实际结果:当我添加第二管道连接到剪切命令时,结果是它挂起,因为如果它等待输入(在你不知道的情况下)

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