getting the stanza names if the pattern found

Hi Friends,
I have a file as below :

machine1:
abc
xyz
qwerty
machine2:
jkl
mno
machine3:
hhh
kkk
qwerty

Now ...i need to find all the stanza names that have the pattern "qwerty'"
in it...( i need to get the output as machine1 and machine3 since qwerty pattern is found there).
Can anybody share there knowledge in this?

Thanks in advance

awk '/machine/{store=$0}
     /qwerty/ {print store}' "file"

output:

# ./test.sh
machine1:
machine3:

Hi ghostdog74,
The output printed is only machine3 not machine1.
Let me put my question again ..

I have a file with many stanzas...as below..

Monday:
designs
velocity
Tuesdaey:
Projetn
Manage
wednesday:
work
velocity
********
(all the non-stanza lines have a space eg ..design,veloocity,manage..etc all have a space at the beginning)

I need to get the stanza names that have the pattern "velocity"
The o/p should be as below...
Monday
Wednesday

can u plz help me...its really imp...

Thanks in advance...

According to your first example data file, ghostdog's awk command should, and indeed does, return machine1 and machine3

Try it again, but type the command carefully. Also, check that your example data file has no typos. The example file I created from your first post returned machine1 and 3 as expected.

Specifically adding a space at the beginning of a search string (for whatever reason you might have...) is easily accomplished:

awk '/machine/{store=$0} / qwerty/ {print store}' "file"

Note the difference from the original:
awk '/machine/{store=$0} /qwerty/ {print store}' "file"

But the original will still return the correct results since "qwerty" (based on the data you provided) is in the string regardless of there being anything before or after the word.

In your second example, the common element in your stanza names would seem to be that they end with a colon.
awk '/:/{store=$0} / velocity/ {print store}' "file"

Hi Ghostdog74 and Flying_Meat,
Thanks to both of u ....the code works as expected..