Help needed to extracting lines

Hello,

I need help in extracting lines that meets following criteria

Grep for a particular word and return line before it, the line that has that word, and line after that

:::::::::::::::::::::::::
Subject
Hi there
My name is Jak
My last name is XYZ
Home Address
::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::

If i grep for Jak the output should give

Hi there
My name is Jak
My last name is XYZ
grep -A1 -B1 Jak file

Yes you can try this

grep -A (num of lines after) -B (num of lines before) Jak file

Cheers,
Adi

With Sed

michaelf>uname
SunOS
michaelf>sed -n 'H
> /Jak/{
> g
> s/.*\n\(.*\n.*\)/\1/
> N
> p
> }' infile
Hi there
My name is Jak
My last name is XYZ
michaelf>

Thanks everyone for prompt help!

grep -C1 Jak file

It will give above yes and below lines