|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Change attribute value in xml using shell script
hi, i am new to unix and i have a problem. -------------------------------------------------------------- sebben.xml Code:
<envelope> <email> sebben@example.com </email> </envelope> script_mail written in the vi editor. Code:
#!/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 Last edited by Scott; 01-25-2013 at 09:39 PM.. Reason: Please use code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
echo "type in your emailadress"
read MAIL
awk -F'>' -v m="$MAIL" '/<email>/{$2=m;}1' OFS='>' sebben.xmlOr use below code if opening & closing tags are in same line: Code:
awk -v m="$MAIL" '/<email>/{gsub(/>.*</,">"m"<");}1' sebben.xml |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
thanks
thank you bipinajith. now i can go to sleep
![]() |
|
#4
|
||||
|
||||
|
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: Code:
<element attribute="AttributeValue">ElementValue</element> |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hacmp user attribute change | newtoaixos | AIX | 2 | 06-15-2012 10:36 AM |
| Extracting the value of an middle attribute tag from XML | mjavalkar | Shell Programming and Scripting | 5 | 04-05-2012 12:48 AM |
| Changing attribute value in xml file using shell | javaholics | Shell Programming and Scripting | 5 | 08-04-2010 08:09 AM |
| Extracting the value of an attribute tag from XML | JesterMania | Shell Programming and Scripting | 5 | 04-25-2010 07:14 PM |
| read xml tag attribute and store it in variable | swetha123 | Shell Programming and Scripting | 5 | 05-29-2009 01:49 AM |
|
|