-   Programming (
-   -   grep lines before and after (

magnum81 08-13-2006 01: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?

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

thedonkdonk 08-13-2006 02: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 03:57 PM

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

theNbomr 07-29-2011 05: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 10:09 PM.