grep -A -B -C 显示行选项
-A是显示匹配后和它后面的n行。
-B是显示匹配行和它前面的n行。
-C是匹配行和它前后各n行。
[root@DESKTOP-U476VLM ~]# cat test 1 2 3 a 4 5 6 7 [root@DESKTOP-U476VLM ~]# [root@DESKTOP-U476VLM ~]# grep -A 2 a test a 4 5 [root@DESKTOP-U476VLM ~]# grep -B 2 a test 2 3 a [root@DESKTOP-U476VLM ~]# grep -C 2 a test 2 3 a 4 5 [root@DESKTOP-U476VLM ~]#
a为要查找的文字

浙公网安备 33010602011771号