The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Chnage direcortory upon login The One Linux 9 04-13-2008 07:27 PM
Solaris 10 - dtlogin port chnage? kungpow SUN Solaris 5 02-05-2007 04:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2008
Registered User
 

Join Date: Aug 2007
Posts: 46
Stumble this Post!
xml value chnage, need help

Group, I have a xml file like this.

Code:
<roll no="32" Name="test" home="AZ" Type="par">
<Info cid="5">
I have to change the "roll no" to a different value say, 66

i.e. required output:
Code:
<roll no="66" Name="test" home="AZ" Type="par">
<Info cid="5">
Please help. Anything with sed or awk will work


I tried this

Code:
$ MYID=66; sed -e 's+\(roll no=\)\([0-9]*\).*+\1"'$MYID'">+' my.xml
<roll no="66">
<Info cid="5">
But Name, home and Type got dis-appeared.

HTH,
jkl_jkl
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-07-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,658
Stumble this Post!
Quote:
Originally Posted by jkl_jkl View Post
Group, I have a xml file like this.

Code:
<roll no="32" Name="test" home="AZ" Type="par">
<Info cid="5">
I have to change the "roll no" to a different value say, 66

i.e. required output:
Code:
<roll no="66" Name="test" home="AZ" Type="par">
<Info cid="5">
Please help. Anything with sed or awk will work


I tried this

Code:
$ MYID=66; sed -e 's+\(roll no=\)\([0-9]*\).*+\1"'$MYID'">+' my.xml
<roll no="66">
<Info cid="5">
But Name, home and Type got dis-appeared.

HTH,
jkl_jkl
Drop the .* in the regex string. Drop the > in the replacement string.
Code:
MYID=66; sed -e "s+\(roll no=.\)\([0-9]*\)+\1$MYID+" my.xml
Reply With Quote
  #3 (permalink)  
Old 02-07-2008
Registered User
 

Join Date: Aug 2007
Posts: 46
Stumble this Post!
vino, thats a real quick one from you. Thanks a lot :-)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:17 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0