首页 > grep 搜索日志,如何同时显示匹配结果的前后 10 行

grep 搜索日志,如何同时显示匹配结果的前后 10 行

由于日志文件很大,只好用 grep 搜索系统日志定位错误信息,但是 grep 默认展示的匹配的当前行。

我希望能展示当前行,以及之前的 10 行及之后的 10 行,有什么解决方法吗?


grep -A 10 -B 10 pattern content

-A 是匹配行之前的行数,-B 是之后的行数。


  -B, --before-context=NUM  print NUM lines of leading context
  -A, --after-context=NUM   print NUM lines of trailing context
  -C, --context=NUM         print NUM lines of output context
【热门文章】
【热门文章】