LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-07-2011, 03:50 AM   #1
nano2
Member
 
Registered: May 2007
Posts: 100

Rep: Reputation: 15
replacing text in xml file using sed


Hi

I am trying to replace the Valuebdea8cda8c5db7bd with BLAH globally using sed

the data value i.e Valuebdea8cda8c5db7bd will be different value throughout the xml file .

Code:
<data>Valuebdea8cda8c5db7bd</data>

sed 's#\(<data>\)*\(/data>\)#\1'BLAH<'\2#g' xmlfile.xml
Anyone spot why this not correct ?
 
Old 11-07-2011, 04:18 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
It misses the dot before the asterisk:
Code:
sed 's#\(data>\).*\(;/data>\)#\1BLAH\&lt\2#g' xmlfile.xml
 
Old 11-07-2011, 06:16 AM   #3
nano2
Member
 
Registered: May 2007
Posts: 100

Original Poster
Rep: Reputation: 15
Thanks but it doesn't update the file (xmlfile.xml)

i tried placing sed -i before but it creates a new file ...

Any ideas how i can update the file with the new value ?
 
Old 11-07-2011, 06:55 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Indeed, using sed -i:
Code:
sed -i 's#\(data>\).*\(;/data>\)#\1BLAH\&lt\2#g' xmlfile.xml
You sure the original file has not been modified? Try
Code:
sed -i.bck 's#\(data>\).*\(;/data>\)#\1BLAH\&lt\2#g' xmlfile.xml
so that it creates a backup copy of the original file (named xmlfile.xml.bck) that you can use later to check the differences.
 
  


Reply

Tags
bash sed find


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
replacing text with an http link with sed? crypted Programming 4 12-10-2010 12:03 PM
Replacing the text in same file using SED command mariakumar Linux - General 9 10-12-2010 12:20 AM
[SOLVED] Sed - Replacing only text with several specific lines excluded Potatos Linux - Newbie 6 06-17-2010 11:51 PM
Replacing text in files without using sed dfresh4130 Programming 16 05-28-2009 10:13 AM
Replacing text on specific lines with sed or awk? Lantzvillian Linux - Newbie 5 10-17-2007 09:00 AM


All times are GMT -5. The time now is 01:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration