Replace a string in a xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace a string in a xml file
# 1  
Old 12-14-2015
Replace a string in a xml file

Hello,

I have below xml file, I want to find line default-value and replace the string within quotes followed by default-value "moni/Websphere/". Replace moni/Websphere/ with monitor/AMQ/

Code:
<monitor>
        <name>WebsphereMqMonitor</name>
        <type>managed</type>
<argument name="config-file" is-required="false" default-value="moni/Websphere"/>
                </java-task>
        </monitor-run-task>
</monitor>


Last edited by Don Cragun; 12-14-2015 at 11:45 PM.. Reason: Add CODE AND ICODE tags.
# 2  
Old 12-14-2015
What have you tried to solve this problem?

What operating system are you using?

What shell are you using?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 12-15-2015
Code:
bash-3.2$ sed "s/default-value.*/default-value=\"monitor\/AMQ\"\/>/" t.txt
<monitor>
        <name>WebsphereMqMonitor</name>
        <type>managed</type>
<argument name="config-file" is-required="false" default-value="monitor/AMQ"/>
                </java-task>
        </monitor-run-task>
</monitor>

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 12-15-2015
Above will replace every occurrence of a default value. Make it a bit more specific:
Code:
sed "/default-value/ s/moni\/Websphere/monitor\/AMQ/" file


Last edited by RudiC; 12-15-2015 at 05:03 PM.. Reason: typo
This User Gave Thanks to RudiC For This Post:
# 5  
Old 12-16-2015
Download Notepad ++ , it will make life simpler. It supports Regular Expressions Which Notpad doesn't. Refer the attached pic
Replace a string in a xml file-picjpg

Last edited by looney; 12-16-2015 at 02:00 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

2. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

3. Shell Programming and Scripting

Search and replace the string with new word using xml tags

Hi All i need to replace the url1 inside <remote> tag in below xml in first instance and in the second instance with url2. any help appreciated <locations> <hudson.scm.SubversionSCM_-ModuleLocation> <remote>https://svn2015.com/svn/repos/internalshard</remote> ... (4 Replies)
Discussion started by: madankumar.t@hp
4 Replies

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

5. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

6. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

7. UNIX for Dummies Questions & Answers

replace %20 in xml file

Hi, I'd like to use sed in order to replace %20 and other "special" characters that are represented with % and some number combination in xml file. Typical line looks like this: /Users/imac1/Music/iTunes/iTunes... (6 Replies)
Discussion started by: andrejm
6 Replies

8. Shell Programming and Scripting

Help needed :Search and Replace a string pattern with empty in an xml file in unix

Search and Replace a string pattern with empty in an xml file in unix: My xml file would be like this : <Accounts><Name>Harish</Name><mobile>90844444444444445999 </mobile><TRIG>srcujim-1</TRIG></Accounts><Accounts><Name>Satish</Name><mobile>908999</mobile><TRIG>ettertrtt-1</TRIG></Accounts> ... (1 Reply)
Discussion started by: harish_s_ampeo
1 Replies

9. Shell Programming and Scripting

replace string in XML with sed

Greetings, I have an XML : file.xml <component> <name>abcd</name> <value>1234</value> </component> I am using sed to replace abcd with the desired value dynamically without knowing the actual value. sed 's/<name>./]\{1,\}<\/name>/<name>ijkl<\/name>/' file.xml > newfile.xml I... (6 Replies)
Discussion started by: chiru_h
6 Replies
Login or Register to Ask a Question