Place Holder Products Code
Bash MySQL
Notes Return of the Fed Login
Admin Control Panel Email Control Panel Product Control Panel Debug Info Beacon Create Snippet Tag Control Panel

Show lines surrounding match with grep

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.

Comments:

No Comments Yet!