How to grep (say)last-3 and next-3 lines of Desired Pattern

Hi All,

OS-Type=Sun-OS 5.8 Sparc9 Processor

Can I grep the previous 4 lines and next 4 lines of a matched pattern(context grep)?
For example here we need to monitor logs of live traffic.The data obtained from "tail -f LiveTrafficData.log"
looks something like this:-
----------------------------
Sender-ip=10.123.32.34 //Useful Info
Junk Parameter=blah
Blah Parameter=more blah
Packet-state=start //Useful Info
Policy-type=test-value-policy //Useful Info
Some more blah
blah blah
user-profile-type=host
user-location=njs-234 //Useful Info
....
...
Similar sort of repetitive data
-------------------------------
Now here the lines which are of concern to me are only policy-type,packet-state,service-ip and user-location,
i.e., I need to ascertain sender-ip and user-location only and only when Policy-type=<desired pattern> AND
Packet-state=<desired pattern2>.

Also note it is from live traffic, so we need to work on "tail -f" of whatever log we are getting,i.e. we need to work on Standard Input and not file.

Any help is welcome.

Thanks and Regards.

P.S:-I went through the internet,but I dont have "grep -A num" or "vmsgrep" or "cgrep".
Also,as it is fresh and accumulating log,so I probably cant store in a file, ie I need to work on Standard Input,not file

if you dont have grep -A/-B you would do this with awk or perl.
red a line from stdin
store the line in a ringbuffer or in an array.
make shure old lines are deleted from the buffer.
if a line maches a pattern print out the buffer and the line . empty the buffer.
the following 3 lines can be printed by resetting a counter which is encresed every time a line is written.
a nice job for awk and a demanding task to learn it

Hi Demwz
thanx for the reply
But its certainly easier said than done.
Anyway will try to learn Awk/Perl

Thanx

someone else did already

grep -E -B 19 -A 26 "^pattern +[1-9]" input.file
# or
awk '$1=="pattern" && $2>0{for(i=0;i<19;i++)print a[(i+NR)%19];print;for(i=0;i<26;i++){getline;print}}{a[NR%19]=$0}' input.file

see printing lines before and after a match - AWK - Tek-Tips