Visit Our UNIX and Linux User Community

Need to replace particular content in a xml file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to replace particular content in a xml file
# 1  
Old 01-29-2012
Need to replace particular content in a xml file

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.

<Style ss:ID="ColumnHeader1">

Replace with:
 <Style ss:ID="ColumnHeader1">
    <Border ss:Position="Bottom" ss:LineStyle="Continuous"ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>

Thanks In Advance

Last edited by Franklin52; 01-29-2012 at 09:16 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 01-29-2012
sed '/ColumnHeader1.*/ { i\
<Border ss:Position="Bottom" ss:LineStyle="Continuous"ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>

Last edited by Franklin52; 01-29-2012 at 09:16 AM.. Reason: Please use code tags for data and code samples, thank you
# 3  
Old 01-29-2012
val='<Borders>\n<Border ss:Position="Bottom" ss:LineStyle="Continuous"ss:Weight="1"/>\n<Border ss:Position="Top"
 ss:LineStyle="Continuous" ss:Weight="1"/>\n</Borders>'

sed '/<Style ss:ID="ColumnHeader1">/ a '"$val"' ' infile

To make the changes inline, use -i option
sed -i '/<Style ss:ID="ColumnHeader1">/ a '"$val"' ' infile

# 4  
Old 01-30-2012
Hi Ahamed,
I am getting the below error while executing your solution.
sed: Function /<Style ss:ID="ColumnHeader1">/ a <Borders>\n<Border ss:Position="Bottom" ss:LineStyle="Continuous"ss:Weight="1"/>\n<Border ss:Position="Top" cannot be parsed.

Can you look into this?

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-30-2012 at 04:34 AM.. Reason: Please use code tags for code and data samples, thank you
# 5  
Old 01-30-2012
You should use the "$val" in sed. Did you do that? And moreover it should be one single line literally separated by \n.


Previous Thread | Next Thread
Test Your Knowledge in Computers #59
Difficulty: Easy
A compiler is a software utility that translates a program written in high-level language into machine-level language.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace content from a file and save

Hi, Right now there is a file called 'qm.ini' which is owned by mqm:mqm and I am trying to replace a line from this file with something else and save. I am using the below perl command to replace and save within a shell script with a different user called 'mqadm' which is also part of mqm... (1 Reply)
Discussion started by: bdpl
1 Replies

2. Shell Programming and Scripting

Replace file name with Space as content

Hi, I am having a files in my directory like this: 2014 1049_file1.txt 2014 1050_file2.txt 2014 1110_file3.txt 2014 1145_file4.txt 2014 2049_file5.txt I need to replace the above file names like this without changing the content of filename: file1.txt file2.txt file3.txt... (10 Replies)
Discussion started by: rohit_shinez
10 Replies

3. UNIX for Dummies Questions & Answers

Grep content in xml file

I have an xml file with header as below. <Provider xmlns="" xmlns:xsi="" xsi:schemaLocation=" 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

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

5. Shell Programming and Scripting

Sed: replace content from file with the content from file

Hi, I am having trouble while using 'sed' with reading files. Please help. I have 3 files. File A, file B and file C. I want to find content of file B in file A and replace it by content in file C. Thanks a lot!! Here is a sample of my question. e.g. (file A: a.txt; file B: b.txt; file... (3 Replies)
Discussion started by: dirkaulo
3 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

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

8. Shell Programming and Scripting

Replace file content after checking value

Our system is receiving one feed from the third party. One of the field in the flat file is ID which id from position 19 to 27. In some cases this ID is coming as 9 zeros (000000000) or 1 right padded zero. ( 0) For these specific records I want to replace fthis field with blank... (3 Replies)
Discussion started by: varunrbs
3 Replies

9. Shell Programming and Scripting

How to replace some content of a file and write with a new name

Hi I have a control file which looks like this LOAD DATA INFILE '/home/scott/XXX.dat' PRESERVE BLANKS ............. ............. how can i change the content of this file and replace the file in the second line with anothe file name and write it back with another name to the disk? ... (5 Replies)
Discussion started by: mwrg
5 Replies

10. Shell Programming and Scripting

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> ... (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

Featured Tech Videos