grep string & next n lines

need help on this. let say i hv 1 file contains as below:

STRING
Description bla bla bla
Description yada yada yada
Data bla bla
Data yada yada

how do i want to display n lines after the string?

thanks in advance!

You never mentioned your OS version

GNU grep has the following:

       -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.

       -C NUM, --context=NUM
              Print  NUM lines of output context.  Places a line containing --
              between contiguous groups of matches.

thanks! it worked under GNU grep, but how about NON-GNU grep like in solaris?

Don't know about non-GNU grep, but you could use sed instead, something like:-

sed -n '/STRING/,$p' filename|head -$n

(where $n is the number of lines you want after the match)

I am not sure about grep. But sed would help.

sed -n -e '/pattern-matched/{N;N;p}' ashterix.txt

will print the matching line and 2 lines that follow it.

Vino

it worked! thanks grasper & vino

Thats much more elegant !

Using awk...

awk '/STRING/{cnt=3}cnt-->0' filename

With GNU sed...

sed -n '/somestring/,+4p' somefile

To print the line containing somestring, plus the next four lines.

Cheers
ZB