Grep Option

Hi,

I was wondering, if there is any option with Grep, so that i can have couple of lines appearing before and after the search line within a result ?

Thanks in Advance.

Rgds - Prince.

-A NUM, --after-context=NUM
Print NUM lines of trailing context after matching lines.
Places a line containing -- between contiguous groups of
matches.

-B NUM, --before-context=NUM
Print NUM lines of leading context before matching lines.
Places a line containing -- between contiguous groups of
matches.

Yes there are options A and B for after-context and before-context. Check whether grep in your system has there options. If not then you can use awk or sed command.

if you have ggrep in your system you can use it too, calling it from /usr/sfw/bin/ggrep

ggrep "pattern" -A 2 -B 4  FILE

2 lines after, 4 lines before the pattern

This is what i was looking for - /usr/sfw/bin/ggrep.

Thanks everyone.