Shell Script to identify the line number containing a particular "string"

Hi,

I have a log file, where i am required to identify the line number, where a particular string/line appears in the log file.

And then copy 200 lines above that line number to a new file.

Can someone provide pointers on how to write this script or what command to be used ?

Any help would be highly appreciated.

Thanks in advnace,

Does your grep support lines matching before matching string ? .. else you need to use awk / sed

check with man grep

In Linux I am doing like:

grep -B 200 "search string" script_name.sh > new_file

Check man grep in the UNIX flavor u r using. For further details.