的grep管道不与尾巴工作吗? [英] Piping of grep is not working with tail?

查看:103
本文介绍了的grep管道不与尾巴工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过检查日志来调试一个场景,这里是我的命令

I am trying to debug one scenario by checking the logs, here is my command

tail -f eclipse.log | grep 'enimation' | grep  -i 'tap'

基本上,我想的是,所有行的,我打印线,在它enimation,那么所有的动画,我希望看到的动画在它的龙头。

Basically what I am trying to to is that, of all of the line, I am printing lines with enimation in it, then of all of the animation, I want to see the animation with "tap" in it.

下面是它被返回空的结果sammple数据

Here is the sammple data for which it is returning empty results

*******enimation error*********TapExpand
*******enimation error*********TapShrink

这是返回空的结果。

而如果我运行此命令

 tail -f eclipse.log | grep  -i 'enimation.*tap'

它返回正确的结果。可有人请给我解释一下,什么是上面的两个命令,以及为什么没有在结果的差异之间的区别。他们似乎都等同于我。

it returns correct results. Can someone please explain to me, what is the difference between the above two command and why there is a discrepancy in the results. They both seem identical to me.

推荐答案

的grep 正在缓冲它的输出。告诉GNU的grep吐出输出的行由行您需要使用 - 在行缓冲选项grep的,使其工作:

grep is buffering it's output. To tell GNU grep to spit out output line-by-line you need to use --line-buffered option in grep to make it work:

tail -f eclipse.log | grep --line-buffered 'enimation' | grep --line-buffered -i 'tap'

的grep人

--line-buffered
    Force output to be line buffered.  By default, output is line buffered when standard
    output is a terminal and block buffered otherwise.

这篇关于的grep管道不与尾巴工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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