2

I've got an xml property like so:

<property name="foo" value="bar"/>

And would like to modify the value "bar" to be anything else. Any standard command line tools to do so? I'm having trouble getting sed to play nice, I'm not sure which characters I should be escaping.

2 Answers 2

1

xmlstarlet is a pretty full-featured XML tool.

xmlstarlet ed --update /property/@value -v qux <<END
<property name="foo" value="bar"/> 
END
<?xml version="1.0"?>
<property name="foo" value="qux"/>

Add -O to omit the XML declaration line.

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately I don't have control over the machine this is running on, so it's just standard tools for me :( sed, awk, etc.
1

Using awk

echo '<property name="foo" value="bar"/>' | awk '{sub(/bar/,"new")}1'
<property name="foo" value="new"/>

another version

echo '<property name="foo" value="bar"/>' | awk -F\" '{$4="new"}1' OFS=\"
<property name="foo" value="new"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.