1

I want to update

<MySettingsSettings enabled="false" logFilePath="E:\server.log" />

to

<MySettingsSettings enabled="true" logFilePath="D:\server.log" />

How can I do this through sed? or is there any other way to update in a windows server?

3

My suggestion, is that you use a real programming language that can actually parse and update XML/HTML documents properly. Using sed to update XML/HTML will probably fail in the long run.

| improve this answer | |
  • +1 : Didn't notice this was a XML file. – Studer Feb 18 '10 at 2:25
  • I am just assuming it is xml/html. But it sure looks like it. – Zoredache Feb 18 '10 at 2:37
1

A simple substitution from your example can be done like this:

sed -e 's/enabled="true"/enabled="false"/g' -e 's/logFilePath="D:/logFilePath="C:/g' myfile.xml

However, I would agree with Zoredache's warning that unless you are only doing a very simple string replacement inside XML, you'd be better off with a language that has libraries available specifically built for parsing XML.

A great resource for a multitude of handy sed commands is the "sed one-liner" file:

http://sed.sourceforge.net/sed1line.txt

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.