It can sometimes be useful to have grep return the lines that come directly before or after a match. This can be easily achieved in the GNU version of grep.
In addition to being recursive and showing the line number, the following shows 2 lines before each match, and 4 lines after.
grep -rn . -A 4 -B 2 -e pattern
Here -A
and -B
represent lines after and lines before. The same number can be used for both with the -C
switch.
No Comments Yet!