Change attribute value in xml using shell script

hi, i am new to unix and i have a problem.
--------------------------------------------------------------
sebben.xml

<envelope>
<email> sebben@example.com 
</email>
</envelope>

script_mail written in the vi editor.

#!/bin/sh
script to change the value in attribute <email>
echo "type in your emailadress"
read MAIL

sed??

the script and the xml file is in the same catalog.

now what i want the script to do is to change the value in attribute <email> who currently is sebben@example.com to what the user type in. the attribute email should always change to what is typed in and erase the current email in <email>

i have tryed to use the sed command but i cant get it to work. I could really use some help if someone has some time over.

thanks/ sebben

echo "type in your emailadress"
read MAIL
awk -F'>' -v m="$MAIL" '/<email>/{$2=m;}1' OFS='>' sebben.xml

Or use below code if opening & closing tags are in same line:

awk -v m="$MAIL" '/<email>/{gsub(/>.*</,">"m"<");}1' sebben.xml

thank you bipinajith. now i can go to sleep :slight_smile:

A quick note. As far as XML is concerned, you are trying to change the value of an element - not an attribute.

The following shows the difference:

<element attribute="AttributeValue">ElementValue</element>