I'm bashing my head against the wall with this one. How do I do a regex replacement with sed
on text that contains a newline?
I need to replace the value of the "version" XML element shown below. There are multiple version elements so I want to replace the one that comes after the "name" element.
<name>MyName</name>
<version>old</version>
Here's my command:
sed -i -E "s@(\s*<name>$NAME</name>\n\s*<version>)$VERSION_OLD(</version>)@\1$VERSION_NEW\2@g" $myfile.txt
Now as far as I know there is a way to make sed
work with a newline character, but I can't figure it out. I've already used sed in my script so ideally I'd prefer to re-use it instead of say perl
.