Help search in files

Hi guys. I had alot of luck last time I came here but not so much this time. I've searched around the forums for awhile but can't find exactly what I'm looking for. Here is my problem.

I wrote a program that askes the user some questions. Then based off the info they entered it looks to find if a lead came in through our archives. What I need to do is when it finds $unique in the file then search UP to find the word Event arrived and display that. It isn't a set number of lines above. it can be from 1 - 100 lines above.

Archive:
XXXXXXXX
XXXXXXXX
Event arrived 13:45
XXXXXXXX
XXXXXXXX
XXXXXXXX
$unique

#!/bin/sh
############################################################
# Project: Search for Leads
# Date: 2-26-08
# Name: Adam Fowler
############################################################

clear
folder=workingdir
echo "This program will help you search for leads"
echo ""
echo "What month was the lead sent? Use 2 numbers"
read month
echo "What day was the lead sent? Use 2 numbers"
read day
echo "What hour was the lead sent? Use 2 numbers in 24hr"
read hour
echo "What do you want to search for?"
read unique
cd /usr/local/vitria/BW31/backups/archiveU174/
cp Partners.Leads.channels.UnprocessedEmail.2008-$month-$day\_$hour* $folder
cp Partners.Leads.channels.EmailIn.2008-$month-$day\_$hour* $folder
cp B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day\_$hour* $folder
cd $folder
zipped="B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day"_"$hour.gz Partners.Leads.channels.EmailIn.2008-$month-$day"_
"$hour.gz Partners.Leads.channels.UnprocessedEmail.2008-$month-$day"_"$hour.gz"
zipped2=`echo *.gz`
if [ "$zipped2" = "$zipped" ]
then
        echo "Unzipping files..."
        gunzip *.gz
        echo "Done unzipping"
fi
echo "*********************************Inbound"******************************************
fgrep "$unique" Partners.Leads.channels.EmailIn.2008-$month-$day\_$hour*
Search for $unique in the file
Search up for the words "Event arrived"
echo "*********************************Outbound"******************************************
fgrep "$unique" B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day\_$hour*
Search for $unique in the file
Search up for the words "Event arrived"
echo "****************************Outbound for Unparced***********************************"
fgrep "$unique" Partners.Leads.channels.UnprocessedEmail.2008-$month-$day\_$hour*
Search for $unique in the file
Search up for the words "Event arrived"
rm Partners.Leads.channels.EmailIn.2008-$month-$day\_$hour*
rm B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day\_$hour*
rm Partners.Leads.channels.UnprocessedEmail.2008-$month-$day\_$hour*
echo "************************************************************************************"
echo "*You should see a result for Inbound and outbound                                  *"
echo "*If you see more than 1 of each of these then find something else to search for    *"
echo "*They may have sent the lead multiple times. Check to see if the leads are the same*"
echo "*If you see it in inbound and nothing else then contact RIH support and tell       *"
echo "*them everything that you entered for the search.                                  *"
echo "************************************************************************************"

Don't grep - use awk

awk -v unique="$unique" ' {
              if($1 ~ /^Event/) {event=$0}
              if(index($0, unique)>0) { print event, $0; exit}
              } ' inputfilename

Thanks for the super fast response.. Will this work with Event arrived? Sorry for newb question. I've never used awk. Also I don't know if you picked up on this but "$unique" is not in the file. It is the variable that is written when asked the question "What do you want to search for?" Will this awk search for the word $unique or Homer Simpson? When i tried what you have i got this error

awk: syntax error near line 1
awk: bailing out near line 1

assuming you're on Solaris...

try nawk or /usr/xpg4/bin/awk

Thank you so much!!! works great! Thanks to both of you!.

Full code below for those that need it. thanks again

#!/bin/sh
############################################################
# Project: Search for Leads
# Date: 2-26-08
# Name: Adam Fowler
############################################################

clear
folder=workingdir
echo "This program will help you search for leads"
echo ""
echo "What month was the lead sent? Use 2 numbers"
read month
echo "What day was the lead sent? Use 2 numbers"
read day
echo "What hour was the lead sent? Use 2 numbers in 24hr"
read hour
echo "What do you want to search for?"
read unique
cd /usr/local/vitria/BW31/backups/archiveU174/

# copy archives to working directory
cp Partners.Leads.channels.UnprocessedEmail.2008-$month-$day\_$hour* $folder
cp Partners.Leads.channels.EmailIn.2008-$month-$day\_$hour* $folder
cp B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day\_$hour* $folder
cd $folder

# Check to see if they are zipped and unzip them
zipped="B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day"_"$hour.gz Partners.Leads.channels.EmailIn.2008-$month-$day"_"$hour.gz Par
tners.Leads.channels.UnprocessedEmail.2008-$month-$day"_"$hour.gz"
zipped2=`echo *.gz`
if [ "$zipped2" = "$zipped" ]
then
        echo "Unzipping files..."
        gunzip *.gz
        echo "Done unzipping"
fi
echo "*********************************Inbound"******************************************
/usr/xpg4/bin/awk -v unique="$unique" ' {
              if($1 ~ /^Event/) {event=$0}
              if(index($0, unique)>0) { print event, $0; exit}
              } ' Partners.Leads.channels.EmailIn.2008-$month-$day\_$hour
echo "*********************************Outbound"******************************************
/usr/xpg4/bin/awk -v unique="$unique" ' {
              if($1 ~ /^Event/) {event=$0}
              if(index($0, unique)>0) { print event, $0; exit}
              } ' B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day\_$hour
echo "****************************Outbound for Unparced***********************************"
/usr/xpg4/bin/awk -v unique="$unique" ' {
              if($1 ~ /^Event/) {event=$0}
              if(index($0, unique)>0) { print event, $0; exit}
              } ' Partners.Leads.channels.UnprocessedEmail.2008-$month-$day\_$hour

rm Partners.Leads.channels.EmailIn.2008-$month-$day\_$hour*
rm B2B.Outbound.CMHttpsHigh.channels.Out.2008-$month-$day\_$hour*
rm Partners.Leads.channels.UnprocessedEmail.2008-$month-$day\_$hour*
echo "************************************************************************************"