Visit Our UNIX and Linux User Community


xml value chnage, need help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting xml value chnage, need help
# 1  
Old 02-08-2008
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
# 2  
Old 02-08-2008
Quote:
Originally Posted by jkl_jkl
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

# 3  
Old 02-08-2008
vino, thats a real quick one from you. Thanks a lot :-)

Previous Thread | Next Thread
Test Your Knowledge in Computers #261
Difficulty: Easy
On 8 June 1954, Alan Turing's housekeeper found him dead at the age of 41; a suicide by cyanide poisoning.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies

2. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

3. Shell Programming and Scripting

Split xml file into multiple xml based on letterID

Hi All, We need to split a large xml into multiple valid xml with same header(2lines) and footer(last line) for N number of letterId. In the example below we have first 2 lines as header and last line as footer.(They need to be in each split xml file) Header: <?xml version="1.0"... (5 Replies)
Discussion started by: vx04
5 Replies

4. UNIX for Dummies Questions & Answers

How to chnage format and subtract time and date and get average.?

Hello All , Please support for below request how to change format and subtract time and date and get average. xxx 13-OCT-15 11.32.18.241000 AM 13-OCT-15 11.35.49.089080 AM xxx 13-OCT-15 11.32.24.000000 AM 13-OCT-15 11.45.17.810904 AM xxx 13-OCT-15 11.32.25.232000 AM ... (1 Reply)
Discussion started by: mirwasim
1 Replies

5. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

6. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

7. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

8. Red Hat

Chnage direcortory upon login

Hi, I am using Redhat 4AS and I'm planning to change the default directory (/home/psuser) upon login to /opt/directory/. This is my .bash_profile entry: # .bash_profile # Get the aliases and functions if ; then . ~/.bashrc fi # User specific environment and startup programs... (9 Replies)
Discussion started by: The One
9 Replies

9. Solaris

Solaris 10 - dtlogin port chnage?

I have changed my dtlogin port from the deault 177 to 180. When I'm at the Remote Login session screen, how do I specify the port number? (5 Replies)
Discussion started by: kungpow
5 Replies

Featured Tech Videos