Data Extraction From a File

Hi All,

I have a requirement where I have to search the file with some text say "Exception". This exception word can be repeated for more then 10 times.

Suppose the "Exception" word is repeated at line numbers say x=10, 50, 60, 120. Now I want to extract all the lines starting from x-5 to x+5.

for example for x=10 and 50, I want to extract starting from line 5 to line 15 and from line 45 to line 55.

At the end copy all the extracted data to a different file.

I am new to Unix, any pointers or documentation should be helpful to me.

Looking forward for the response.

Thanks
-Ramana.

Hi,

grep -5 "Exception" file

HTH Chris

Hi Chris,

Thanks for the quick response. It works.

Regards
Ramana.

Nice shortcut, I hadn't noticed it in the manpages.