Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grep - return surrounding lines for each hit [closed]

Tags:

grep

I'm using grep in a search that returns significant false-positivies, and it's probably easier for me to identify the good results by inspection, than to write the much more complicated grep expression.

To do that, I need to see more than 1 line for each result.

Can I (How do i) instruct grep to return 1-2 lines above and below each match?

like image 723
blueberryfields Avatar asked Sep 17 '13 16:09

blueberryfields


1 Answers

If you have GNU grep, then:

grep -A 2 -B 2 or grep -C 2
-A stands for after
-B stands for before
-C stands for context (both before and after)

Source and more options: http://unixhelp.ed.ac.uk/CGI/man-cgi?grep

like image 66
ThanksForAllTheFish Avatar answered Nov 10 '22 01:11

ThanksForAllTheFish