我有一个 python 脚本,它报告错误在 17 分钟的时间段内出现在 catalina.out
中的次数。一些错误包含更多信息,显示在错误下方接下来的三行中。不幸的是,我正在寻找的句子包含 []
。我不想使用正则表达式进行搜索。有没有办法关闭正则表达式功能,只做精确搜索?
这是我正在搜索的句子示例:
bob: [2012-08-30 02:58:57.326] ERROR: web.errors.GrailsExceptionResolver Exception occurred when processing request: [GET] /bob/event
谢谢
最佳答案
(假设您使用的是标准 grep 命令)
Is there a way to turn off the regular expression function and only do an exact search?
当然,您可以将 -F
标志传递给 grep
,如下所示:
grep -F "[GET]" catalina.out
请记住将搜索词放在引号中,否则 bash 会以特殊方式解释括号。
关于python - Grep 查找包含 [] 的特定句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7558369/