[CentOS] grep

Jim Perrin jperrin at gmail.com
Tue Aug 28 14:10:25 UTC 2007


On 8/28/07, Scott McClanahan <scott.mcclanahan at trnswrks.com> wrote:
> Not a CentOS specific question, although I am running grep on CentOS 4.3
> but how would you grep out a series of lines in a file starting at a
> specific point.  For instance, if I have a file named foo and I want to
> grep out the next 5 lines after the first and only instance of the
> string "bar" how could I pull that off?  Thanks so much.


'grep -A 5 bar foo' should do the trick.  From the grep manpage ->
-A NUM, --after-context=NUM
              Print NUM lines of trailing context after matching
lines.  Places a line containing -- between contiguous groups of
matches.



-- 
During times of universal deceit, telling the truth becomes a revolutionary act.
George Orwell



More information about the CentOS mailing list