【发布时间】:2020-09-02 09:27:17
【问题描述】:
我想从日志文件中 grep 500 错误代码
tail -f requests.log | egrep " 500 "
它的贪婪的东西hello500或500hello或hello500hello
我只想 grep 500 周围有空格,我该怎么做?
【问题讨论】:
-
您的
egrep仅匹配带有空格的500,请参阅ideone.com/aIFFQl
我想从日志文件中 grep 500 错误代码
tail -f requests.log | egrep " 500 "
它的贪婪的东西hello500或500hello或hello500hello
我只想 grep 500 周围有空格,我该怎么做?
【问题讨论】:
egrep 仅匹配带有空格的500,请参阅ideone.com/aIFFQl
我相信你弄错了,你可以在这里看到:
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" 也会在那里。
【讨论】: