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为要查找的文字

posted @ 2023-06-17 16:16  你说夕阳很美  阅读(368)  评论(0)    收藏  举报