【问题标题】:How to grep with spaces?如何用空格grep?
【发布时间】:2020-09-02 09:27:17
【问题描述】:

我想从日志文件中 grep 500 错误代码

tail -f requests.log | egrep " 500 "

它的贪婪的东西hello500500hellohello500hello

我只想 grep 500 周围有空格,我该怎么做?

【问题讨论】:

标签: terminal grep


【解决方案1】:

我相信你弄错了,你可以在这里看到:

Prompt>cat test_500.log
 a space with 500 space characters
hello500
hello500 with a 500 space

当我在此启动 egrep " 500 " 时,我得到的是:

 a space with 500 space characters
hello500 with a 500 space

你可以反应“看,你也有hello500的结果”,但现在让我给你看看结果,由grep找到,粗体:

包含 500 个空格字符的空格
带有 500 空格的 hello500

Grep 返回整行。如果 "hello500" 的同一行中的空格之间有 500,则 "hello500" 也会在那里。

【讨论】:

    猜你喜欢
    • 2012-10-24
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    相关资源
    最近更新 更多