Locating correct XML tags


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Locating correct XML tags
# 8  
Old 08-15-2006
Yes, you ARE running under Solaris.
Don't use plain old 'awk', but rather the posted alternatives no matter what other changes you'll be making to the script itself.
# 9  
Old 08-15-2006
oh really? Thank you, I had not been doing in UNIX for a while now, kinda floating away from me. Thank you for the advice.
# 10  
Old 08-15-2006
tempReplacement=$(nawk '
/<Tag ABC=1>/ {
tagnum += 1
}
/<tag_value1>/ && tagnum==2 {
print "<tag_value1>some_other_value</tag_value1>" ;
next
}
1
' file.xml)

Well it worked, right now i am trying to fix it as well, because it will change other <tag_value1> as i move on to another xml file that contain have the same thing as the first one except that <tag_value1> is all over the place. aigles' code worked perfect if the second <Tag> is the last one in the xml file. The other one xml file contain a lot more <tag_value1>. Right now I am trying to tweak aigles code to change just the second

<Tag ABC=1>
<tag_value1>some_value</tag_value1>
</Tag>

and not the rest of the <tag_value1> that come after the second <Tag>.

Thank you both for replying. I really appreciate both your help (especially aigles).
# 11  
Old 08-15-2006
NVM, figured it out, instead of using next to loop through everything, I had used exit 1 as soon as the second tag is located. Thank you.

BTW do you know if i could use sed to change the value though? because using the aigles' code, i am printing to the file instead of updating it.

Cheers.
# 12  
Old 08-16-2006
If you want to update the file :
Code:
awk ' ...... ' file.xml > file.xml.tmp
mv file.xml.tmp file.xml


Jean-Pierre.
# 13  
Old 08-16-2006
Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Solaris

Locating files!

My question is : -How do I locate files of specific user in specific folder. In other words, How do I find files that belong only to "root" user, in /etc folder? (5 Replies)
Discussion started by: alexex666
5 Replies

3. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

4. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 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

Data between XML Tags

<?xml version="1.0" encoding="iso-8859-1" ?> <TABLE> <TEST> <ID> 123 </ID> <name> abc </name> </TEST> <TEST> <ID> 123 </ID> <name> abc2 </name> </TEST> </TABLE> <TABLE> <TEST> <ID> 456 </ID> <name> def </name> </TEST> <TEST> ... (8 Replies)
Discussion started by: eskay
8 Replies

8. UNIX for Advanced & Expert Users

Search in xml tags

I have a xml file like below. I want to search in <msg>, if found corresponding tag path needs to fetch. for eg: for the message 'RM1659 Boeing Exception Management' it should return /trunk/talend/source/SITA_SP7/Job_Designs/DeferredOutputs/SmartViewFiles/DO_Smartview.zip For message it can... (2 Replies)
Discussion started by: svenkatareddy
2 Replies

9. Shell Programming and Scripting

Why are the xml tags not visible?

Could some one please tell me why, when I run the following php code: <HTML> <HEAD> <TITLE></TITLE> </HEAD> <BODY> <?php $readfile = file("rss_file.xml"); for ($k=0; $k<=count($readfile)-1; $k++) { echo "$readfile<br>"; } </BODY> </HTML> the tags do not appear in... (1 Reply)
Discussion started by: photon
1 Replies

10. Shell Programming and Scripting

Grep xml tags

Hi I want to get the value between to XML tags as follows <EAN>12345</EAN> so i would want to return 12345. i have tried sed and awk but can't do it. can anyone help? (9 Replies)
Discussion started by: handak9
9 Replies
Login or Register to Ask a Question