sed command for copying the contents of other file replacing it another file on specifc pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed command for copying the contents of other file replacing it another file on specifc pattern
# 1  
Old 01-26-2011
sed command for copying the contents of other file replacing it another file on specifc pattern

We have 2 file XML files - FILE1.XML and FILE2.xml - we need copy the contents of FILE1.XML and replace in FILE2.xml pattern "<assignedAttributeList></assignedAttributeList>"
FILE1.XML
1. <itemList>
2. <item type="Manufactured">
3. <resourceCode>431048</resourceCode>
4. <assignedAttributeList></assignedAttributeList>
5. </item>
6. <item type="Manufactured">
7. <resourceCode>431079</resourceCode>
8. <assignedAttributeList></assignedAttributeList>
9. </item>
10. </itemList>
FILE2.XML
<assignedAttributeList>
<assignedAttribute>
<attributeCode>Dia</attributeCode>
<attributeValueCode>18"</attributeValueCode>
</assignedAttribute>
<assignedAttribute>
<attributeCode>Base</attributeCode>
<attributeValueCode>22V50FM1</attributeValueCode>
</assignedAttribute>
<assignedAttributeList>
Final FILE1.XML should be like this
------------------------------------
1. <itemList>
2. <item type="Manufactured">
3. <resourceCode>431048</resourceCode>
4. <assignedAttributeList></assignedAttributeList>
5. </item>
6. <item type="Manufactured">
7. <resourceCode>431079</resourceCode>
8. <assignedAttributeList>
<assignedAttribute>
<attributeCode>Dia</attributeCode>
<attributeValueCode>18"</attributeValueCode>
</assignedAttribute>
<assignedAttribute>
<attributeCode>Base</attributeCode>
<attributeValueCode>22V50FM1</attributeValueCode>
</assignedAttribute>
<assignedAttributeList>
9. </item>
10. </itemList>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Copying Contents of a file

Hello all. Is there a command to copy the contents of one file into another file as the first line? (1 Reply)
Discussion started by: 2metal4u
1 Replies

2. Shell Programming and Scripting

sed command to delete a pattern in a file

Hi Everyone, I have an unusual requirement. Here is where i am stuck for sometime now... I have this text file.. lets say .. output.sql... it has lot of entries... here below is part of the entry... .. . . . . . . . . . . . . . . . .... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

sed command to substitute contents from external file

Hi All, I am trying to substitute a line in my existing file with the set of lines from another file. Regarding the existing file, i am sure that the line i am substituting will occur only at one place. I have stored the text to be replaced in another file. I am using below command. cat... (7 Replies)
Discussion started by: chpsam
7 Replies

4. UNIX for Dummies Questions & Answers

Replacing a particular string in all files in folder and file contents

I need to replace all filesnames in a folder as well as its content from AK6 to AK11. Eg Folder has files AK6-Create.xml, AK6-system.py etc.. the files names as well as contents should be changes to AK9-Create.xml, AK9-system.py etc All files are xml and python scripts. ---------- Post... (0 Replies)
Discussion started by: Candid247
0 Replies

5. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

6. UNIX for Dummies Questions & Answers

Help with searching for a file in a directory and copying the contents of that file in a new file

Hi guys, I am a newbie here :wall: I need a script that can search for a file in a directory and copy the contents of that file in a new file. Please help me. :confused: Thanks in advance~ (6 Replies)
Discussion started by: zel2zel
6 Replies

7. Shell Programming and Scripting

Grep a pattern given in one file at other file and display its corresponding contents as output.

***************************************** Right now i have this current system. I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which... (7 Replies)
Discussion started by: abinash
7 Replies

8. Shell Programming and Scripting

replacing text with contents from another file

I'm trying to change the ramfs size in kernel .config automatically. I have a ramfs_size file generated with du -s cat ramfs_size 64512 I want to replace the linux .config's ramdisk size with the above value CONFIG_BLK_DEV_RAM_SIZE=73728 Right now I'm doing something dumb like: ... (3 Replies)
Discussion started by: amoeba
3 Replies

9. Shell Programming and Scripting

Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello, The following sed command is giving error sed: -e expression #1, char 13: unknown option to `s' The sed command is echo "//-----" | sed "s/\/\/---*/$parChk/g" where parChk="//---ee-" How can i print the variable value from sed command ? And is it possible to replace a... (2 Replies)
Discussion started by: frozensmilz
2 Replies

10. Shell Programming and Scripting

Replacing contents in a file from multiple programmes

Hi All, I have a query on Perl. I have a text file which has 3 lines, i want to only replace the first line with my replaced text and keep the rest of the text. FOr eg Before change --> echo:a:pending echo:b:pending echo:c:pending After change ---> echo:a:done echo:b:pending... (1 Reply)
Discussion started by: tosatesh
1 Replies
Login or Register to Ask a Question