For BSD or GNU grep
you can use -B num
to set how many lines before the match and -A num
for the number of lines after the match.
(对于BSD或GNU grep
您可以使用-B num
来设置匹配前的行数和匹配后的行数的-A num
。)
grep -B 3 -A 2 foo README.txt
If you want the same number of lines before and after you can use -C num
.
(如果你想要使用-C num
之前和之后的相同行数。)
grep -C 3 foo README.txt
This will show 3 lines before and 3 lines after.
(这将显示之前的3行和之后的3行。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…