有文件test.log内容如下: aaa bbb ccc ddd eee fff 使用grep的-B选项,显示匹配内容及其前n行。-B表示before。 grep "ccc" test.log -B 2 输出结果为: aaa bbb ccc 使用grep的-A选项,显示匹配内容及其后n行。-A表示after。 grep "ccc" test.log -A 2 输出结果为: ccc ddd eee 使用grep的-C选项,显示匹配内容及其前n行,后n行。 grep "ccc" test.log -C 2