grep exact string from a file

Hi,

I have the following output from a file

zone "adm.test.com" {
abc
test1.db
}
zone "test.com" {
xyz
test2.db
}
zone "1.test.com.sg" {
1abc
test3.db
}
zone "3.test.com.uk" {
1xyz
test4.db
}

I need to grep for "test.com" only, count the lines number and then add 2 to the line number so as to obtain "test2.db".

I tried "grep -n -w test.com" and it greps for multiple instances. How do I grep only exact matches and then do the line count? I am running the script on Solaris 10 OS.

Pls. help. Thanks.

I'd use awk rather than to try to make grep work out of its comfort zone.

awk '
    /zone "test.com"/ {
        getline;
        getline;
        print; exit(0);
    }
'

You can smash it all on one line and have it still be readable:

awk '/zone "test.com"/ { getline; getline; print; exit(0);}'

grep -w is the right option to find the exact string

Through Sed..

sed -n '/\"test.com\"/{n;n;p}' inputfile

input text:

hi how are you doing?
you people are great
your frnd just called me
this pen is yours right? are you sure

and when i grepped it..

# grep -w 'your' inputfile
your frnd just called me

when you used -w grep looked exactly for "your" and it didnt select the word "yours" from the file..which would have been selected if you had not used -w option

On SunOS this should also work..

grep -A2 '"test.com"' file | tail -1

Thanks for all the help. Works fine.