LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   grep lines before and after (http://www.linuxquestions.org/questions/programming-9/grep-lines-before-and-after-473405/)

magnum81 08-13-2006 12:53 AM

grep lines before and after
 
Is there a way to make grep display a certain number or lines before and after the targer search?

Nevermind.
-B n for before
-N n for after
where n is the number of lines

thedonkdonk 08-13-2006 01:03 AM

Yes. Use -A for number of lines before matching line and -B for number of line after matching line. Example.
ifconfig | grep -B 2 inet will outupt lines that will show you all of your interface names that have a IPv4 address.

witkacy26 07-29-2011 02:57 PM

grep lines before and after - correction
 
-A is for [A]fter and -B is for [B]efore :hattip:

theNbomr 07-29-2011 04:52 PM

There is also -C (Context), which shows 'n' lines before & after found text.

--- rod.


All times are GMT -5. The time now is 08:55 AM.