Sponsored Content
Top Forums Shell Programming and Scripting How to add the multiple lines of xml tags before a particular xml tag in a file Post 302661743 by mjavalkar on Monday 25th of June 2012 04:54:17 PM
Old 06-25-2012
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.

Code:
<A>testing_Location</A>
<value>LA</value>
<zone>US</zone>

<B>Region</B>
<value>Russia</value>
<zone>Washington</zone>
<C>Country</C>
<value>Canada</value>
<zone>US</zone>

In the above example, my need to add the following line of code above the <zone> tag:
Code:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>

The Output should display like:

<A>testing_Location</A>
<value>LA</value>
Quote:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>
<zone>US</zone>

<B>Region</B>
<value>Russia</value>
Quote:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>
<zone>Washington</zone>
<C>Country</C>
<value>Canada</value>
Quote:
<name>Continent</name>
<value>XXXXXXXXXXXXXXXXXYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZ</value>
<zone>US</zone>


Please help me out..

Last edited by mjavalkar; 06-25-2012 at 05:57 PM.. Reason: Update of title
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

getting multiple xml tag

sorry for the trouble...... i have this file that contains the following: 00:00:21 Queue key, Queue Name= 00:00:21 Sending Message :<EXGC-EXGU xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <trans_id>EXGC</trans_id> <sys_prefix>GSYS</sys_prefix> ... (3 Replies)
Discussion started by: forevercalz
3 Replies

2. Shell Programming and Scripting

XML tag replacement from different XML file

We have 2 XML file 1. ORIGINAL.xml file and 2. ATTRIBUTE.xml files, In the ORIGINAL.xml we need some modification as <resourceCode>431048</resourceCode>under <item type="Manufactured"> tag - we need to grab the 431048 value from tag and pass it to database table in unix shell script to find the... (0 Replies)
Discussion started by: balrajg
0 Replies

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

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

5. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <gp> <mms>1110012</mms> <tg>988</tg> <mm>LongTime</mm> <lv> <lkid>StartEle=ONE, Desti = Motion</lkid> <kk>12</kk> </lv> <lv> <lkid>StartEle=ONE, Source = Velocity</lkid> <kk>2</kk> </lv> <lv> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

6. Shell Programming and Scripting

Creating multiple xml tag lines in a file

Hi All, Can someone tell me how can we create same xml tag lines based on the number of lines present in other file and replace the Name variable vaule present in other file. basically I have this xml line <typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/> and say I... (4 Replies)
Discussion started by: Optimus81
4 Replies

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

8. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

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

10. 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
XO(1)							    BSD General Commands Manual 						     XO(1)

NAME
xo -- emit formatted output based on format string and arguments SYNOPSIS
xo [-options] [argument...] DESCRIPTION
The xo utility allows command line access to the functionality of the libxo library. Using xo, shell scripts can emit XML, JSON, or HTML using the same commands that emit text output. --close <path> Close tags for the given path --depth <num> Set the depth for pretty printing --help Display this help text --html OR -H Generate HTML output --json OR -J Generate JSON output --leading-xpath <path> Add a prefix to generated XPaths (HTML) --open <path> Open tags for the given path --pretty OR -p Make 'pretty' output (add indent, newlines) --style <style> Generate given style (xml, json, text, html) --text OR -T Generate text output (the default style) --version Display version information --warn OR -W Display warnings in text on stderr --warn-xml Display warnings in xml on stdout --wrap <path> Wrap output in a set of containers --xml OR -X Generate XML output --xpath Add XPath data to HTML output The xo utility accepts a format string suitable for xo_emit(3) and a set of zero or more arguments used to supply data for that string. xo "The {k:name} weighs {:weight/%d} pounds.0 fish 6 TEXT: The fish weighs 6 pounds. XML: <name>fish</name> <weight>6</weight> JSON: "name": "fish", "weight": 6 HTML: <div class="line"> <div class="text">The </div> <div class="data" data-tag="name">fish</div> <div class="text"> weighs </div> <div class="data" data-tag="weight">6</div> <div class="text"> pounds.</div> </div> The --wrap <path> option can be used to wrap emitted content in a specific hierarchy. The path is a set of hierarchical names separated by the '/' character. xo --wrap top/a/b/c '{:tag}' value XML: <top> <a> <b> <c> <tag>value</tag> </c> </b> </a> </top> JSON: "top": { "a": { "b": { "c": { "tag": "value" } } } } The --open <path> and --close <path> can be used to emit hierarchical information without the matching close and open tag. This allows a shell script to emit open tags, data, and then close tags. The --depth option may be used to set the depth for indentation. The --leading-xpath may be used to prepend data to the XPath values used for HTML output style. #!/bin/sh xo --open top/data xo --depth 2 '{tag}' value xo --close top/data XML: <top> <data> <tag>value</tag> </data> </top> JSON: "top": { "data": { "tag": "value" } } EXAMPLE
% xo 'The {:product} is {:status}0 stereo "in route" The stereo is in route % xo -p -X 'The {:product} is {:status}0 stereo "in route" <product>stereo</product> <status>in route</status> ADDITIONAL DOCUMENTATION
Complete documentation can be found on github: http://juniper.github.io/libxo/libxo-manual.html libxo lives on github as: https://github.com/Juniper/libxo The latest release of libxo is available at: https://github.com/Juniper/libxo/releases SEE ALSO
libxo(3), xo_emit(3) HISTORY
The libxo library was added in FreeBSD 11.0. AUTHOR
Phil Shafer BSD
December 4, 2014 BSD
All times are GMT -4. The time now is 01:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy