Search string in unix and print whole matching word

Hi

I have requirement to search string starting with specific characters and print whole matching word in that string.

example

mystr="ATTRIBUTE NAME="Event Name" VALUE="Execute""

I want to search by passing "NAME=" and result should be NAME="Event Name".

i am using below command but that is printing whole line.

grep "NAME=" $mystr

Please help how to achieve above requirement.

Thanks for all your help.
Mallik.

try with -o

 
echo $mystr | grep -o "NAME=" 

I think you need to decide which style of quotes to use where, or escape the inner double quotes with \.

$ mystr="ATTRIBUTE NAME='Event Name' VALUE='Execute'"
$ echo $mystr | grep -o "NAME='[^']*'"
NAME='Event Name'

This helps me a lot.. Thank you very much scottn