Multiply tags in xml


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiply tags in xml
# 1  
Old 05-02-2013
Multiply tags in xml

Please advice best way to do this.
prefered awk or sed

input file :
Code:
<?xml version='1.0' encoding='ISO-8859-1'?>
<myxml>
<UID></UID>
<Dealer>0002</Dealer>
<Range>
  <FromMonths>24</FromMonths>
  <ToMonths>35</ToMonths>
</Range>
</myxml>


desired output :
Code:
]<?xml version='1.0' encoding='ISO-8859-1'?>
<myxml>
<UID></UID>
<Dealer>0002</Dealer>
<Range>
   <FromMonths>24</FromMonths>
   <ToMonths>35</ToMonths>
</Range>
<Range>
   <FromMonths>100</FromMonths>
   <ToMonths>200</ToMonths>
</Range>
<Range>
   <FromMonths>555</FromMonths>
   <ToMonths>666</ToMonths>
</Range>

</myxml>

# 2  
Old 05-02-2013
Can you please enlighten us how you got those numbers: 100, 200, 555, 666? Smilie
# 3  
Old 05-02-2013
^ joda.
I want to hardcode those number in neewly added lines.

even just coping same line (with sane number) is ok.
# 4  
Old 05-02-2013
Ok, here is my suggestion:

1. Create a file with the list of numbers that you want to put:
Code:
$ cat file
24 35
100 200
555 666

2. Run below awk code to generate the XML by reading the file previously created:
Code:
awk '
        BEGIN {
                print "<?xml version=" "\x27" "1.0\x27 encoding=" "\x27" "ISO-8859-1\x27?>"
                print "<myxml>"
                print "<UID></UID>"
                print "<Dealer>0002</Dealer>"
        }
        {
                print "<Range>"
                print OFS "<FromMonths>" $1 "</FromMonths>"
                print OFS "<ToMonths>" $2 "</ToMonths>"
                print "</Range>"
        }
        END {
                print "</myxml>"
        }
' OFS='\t' file

I hope this helps.
This User Gave Thanks to Yoda For This Post:
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. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. Shell Programming and Scripting

All I want to do is Multiply...

All I want to do is find 5!. read num num={1..5} while do f= done echo f Error Msg. line 5: ${1..5} bad substitution line 6: integer expression expected Line 5 is the num=... Line 6 is the "while" statement I am new at this, and I am really, really trying. Please... (14 Replies)
Discussion started by: Ccccc
14 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