"sed" regex help: Replacing characters
- by powerbar
I want to change characters in a XML file by using sed. The input looks like this:
<!-- Input -->
<root>
<tree foo="abcd" bar="abccdcd" />
<dontTouch foo="asd" bar="abc" />
</root>
Now I want to change all c to X in the bar tag of the tree element.
<!-- Output -->
<root>
<tree foo="abcd" bar="abXXdXd" />
<dontTouch foo="asd" bar="abc" />
</root>
How is the correct sed command? Please consider, there can be more than one occurence of c (next to each other or not) in one tag...
I tried this myself, but it won't change multiple c, and it does append a X :(
sed -i 's/\(<tree.*bar=\".*\)c\(.*\"\/>\)/\1X\2/g' Input.xml