【问题标题】:Is it possible to use tail and grep in combination? [duplicate]是否可以结合使用tail和grep? [复制]
【发布时间】:2012-12-16 22:42:57
【问题描述】:

我正在尝试在生产日志中跟踪用户。

可以用吗

tail -f grep "username"

【问题讨论】:

  • 也许tail [...] -f | grep username
  • 使用tailf而不是tail -f效率更高。

标签: linux grep pipeline tail


【解决方案1】:

是的 - 你使用管道。即

tail -f <some filename> | grep 'username'

【讨论】:

    【解决方案2】:

    是的,你可以只使用管道

    tail -f 文件名 | grep 用户名

    【讨论】:

    • 使用tailftail -f
    【解决方案3】:

    ack 命令是一个类似于 grep 的文本查找器,具有专门为此设计的 --passthru 标志。

    由于ack 自动为您匹配颜色代码,您可以使用它来搜索带尾日志文件的输出,并突出显示匹配项,但看到不匹配的行.

    tail -f error.log | ack --passthru whatever
    

    所有带尾日志的行都会显示出来,但是匹配的会被高亮显示。

    确认在http://beyondgrep.com/

    【讨论】:

      【解决方案4】:

      事实上,我发现它使用起来更有效: grep 用户名文件名 |尾巴

      【讨论】:

        猜你喜欢
        • 2015-12-26
        • 2012-04-11
        • 1970-01-01
        • 1970-01-01
        • 2013-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多