appending content in a xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting appending content in a xml file
# 1  
Old 02-18-2009
appending content in a xml file

Please help me on this.....

i have a file which has following content:
<IPCoreProducerConfig>
<Producer>
<config>
<key>machineId</key>
<value>machine1</value>
</config>
<config>
<key>Producer Type</key>
<value>Breakout</value>
</config>
<config>
<key>Protocol</key>
<value>SIP</value>
</config>
</Producer>
</IPCoreProducerConfig>

i want to append same thing again so that the content of file looks like:
<IPCoreProducerConfig>
<Producer>
<config>
<key>machineId</key>
<value>machine1</value>
</config>
<config>
<key>Producer Type</key>
<value>Breakout</value>
</config>
<config>
<key>Protocol</key>
<value>SIP</value>
</config>
</Producer>
<Producer>
<config>
<key>machineId</key>
<value>machine1</value>
</config>
<config>
<key>Producer Type</key>
<value>Breakout</value>
</config>
<config>
<key>Protocol</key>
<value>SIP</value>
</config>
</Producer>
</IPCoreProducerConfig>

Last edited by Aditya.Gurgaon; 02-18-2009 at 02:13 AM..
# 2  
Old 02-18-2009
Power

It may help your need...

#below one is for declaring variable
#-------------------------
v=`sed '/<\IPCoreProducerConfig\>\|<\/IPCoreProducerConfig\>/d' input.filename`

#creating required outputfile
#--------------------------
echo "<IPCoreProducerConfig>" > output.lst
cat input.filename|sed /<\IPCoreProducerConfig\>\|<\/IPCoreProducerConfig\>/d' >> output.filename
echo $v >> output.filename
echo "</IPCoreProducerConfig>" >> output.filename


THanks
Sha
# 3  
Old 02-18-2009
when i am trying to above ..it is not appending
# 4  
Old 02-18-2009
Hi Aditya,

Are you getting any errors when you run above commands..

what was the repsonse that you got..

Thanks
Sha
# 5  
Old 02-18-2009
Another approach with awk, read the file twice, skip the last line the first time and the first line the second time:

Code:
awk '
/<\/IPCoreProducerConfig>/ && NR==FNR{next}
/<IPCoreProducerConfig>/ && NR!=FNR{next}
1' file file

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending content of a file to another file before a specific character

Hi there, i've got a file with this content $ cat file1 Matt Mar The other file has the same number of lines with this content: $ cat file2 20404=767294 23450=32427 is there a way with either using sed, awk or paste to insert the content of file1 before the "=" character? So... (3 Replies)
Discussion started by: nms
3 Replies

2. UNIX for Dummies Questions & Answers

Grep content in xml file

I have an xml file with header as below. <Provider xmlns="http://www.xyzx.gov/xyz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzx.gov/xyz xyz.xsd" SCHEMA_VERSION="2.5" PROVIDER="5"> I want to get the schema version here that is 2.5 and put in a... (7 Replies)
Discussion started by: Ariean
7 Replies

3. Shell Programming and Scripting

Extracting content from xml file

Hello All, Hope you are doing well!!!!! I have a small code in the below format in xml file: <UML:ModelElement.taggedValue> <UML:TaggedValue tag="documentation" value="This sequence&#xA;&#xA;HLD_EA_0001X&#xA;HLD_DOORS_002X"/> <UML:TaggedValue tag="documentation" value="This... (11 Replies)
Discussion started by: suvendu4urs
11 Replies

4. HP-UX

XML tag name content replacement

Hi, Need to replace an XML tag name contents, please provide any suggestions. Scenario is : <abc_def>Value_some_content</abc_def> Expected output : <abc:def>Value_some_content</abc:def> We have many tag with different names & contents in a file or a string. Please help on the... (3 Replies)
Discussion started by: periyasamycse
3 Replies

5. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

6. Shell Programming and Scripting

Create xml file using a content from another xml file

I need to create a xml file(master.xml) with contents from another xml files(children). I have below list of xml files in a temporary location (C:/temp/xmls) 1. child1.xml 2. child2.xml Below is the content of the child1.xml & child2.xml files, child1.xml <root> <emp> ... (3 Replies)
Discussion started by: vel4ever
3 Replies

7. Shell Programming and Scripting

Need to replace particular content in a xml file

Hi, My requirement is to find a text and replace it with another in a XML file. I am new to Unix,Please provide some suggestion to achieve. Find: <Style ss:ID="ColumnHeader1"> Replace with: <Style ss:ID="ColumnHeader1"> <Borders> <Border ss:Position="Bottom"... (4 Replies)
Discussion started by: cnraja
4 Replies

8. Shell Programming and Scripting

Extract XML content from a file

310439 2012-01-11 03:44:42,291 INFO PutServlet:? - Content of the Message is:="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED> 310440 <BATCH_ID>12345678519</BATCH_ID> 310441 <UID>3498748823</UID> 310442 <FEED_TYPE>FULL</FEED_TYPE> 310443 <MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME> 310444... (11 Replies)
Discussion started by: arukuku
11 Replies

9. Shell Programming and Scripting

Appending file content

how to append the contents of filel to the contents of file2?. i.e. file1: 1 2 3 file2: 4 5 6 then the file2 shoud be 4 5 6 1 2 (7 Replies)
Discussion started by: shashwat2691
7 Replies

10. Shell Programming and Scripting

Appending string to xml file using "sed"

Hi folks, Following a section in opmn.xml file: </process-type> <process-type id="OC4J_RiGHTv_IRD1" module-id="OC4J"> <environment> <variable id="LD_LIBRARY_PATH" value="/home/ias/v10.1.2/lib" append="true"/> <variable id="SHLIB_PATH"... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question