I'm using this answer here: https://stackoverflow.com/a/18622953/1797263 to replace a version in a pom.xml file. The problem I'm running into is that it is stripping the preceding whitespace and I want to keep the preceding whitespace. The whitespace could be 2 or 3 tabs or spaces, depending on how the developer formatted the file.
Here is an example:
<dependency>
<groupId>GROUP</groupId>
<artifactId>ARTIFACT</artifactId>
<version>OLD_VERSION</version>
</dependency>
My command: sed -i '/<artifactId>ARTIFACT<\/artifactId>/!b;n;c<version>NEW_VERSION</version>' pom.xml
And my output:
<dependency>
<groupId>GROUP</groupId>
<artifactId>ARTIFACT</artifactId>
<version>NEW_VERSION</version>
</dependency>
Here is what I would like the replacement to look like:
<dependency>
<groupId>GROUP</groupId>
<artifactId>ARTIFACT</artifactId>
<version>NEW_VERSION</version>
</dependency>
I read through the GNU Sed manual and could not find anything that would help.