title: Is it possible to use sed to replace dependencies's version in a pom file?
body: <p>I have a <code>pom.xml</code> file and I want to replace the version inside any of the <code>dependency</code> nodes from <code>0.1-SNAPSHOT</code> to a different version (let's say <code>NEW-VERSION</code>), the only restriction I have is that the replacement should be done only if the <code>groupId</code> matches a particular text, lets say: <code>com.company.xyz</code>. </p>
  
  <p>That being said, let's say this is the <code>dependencies</code> section of my <code>pom.xml</code>:</p>
  
  <pre><code>&lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.company.xyz&lt;/groupId&gt;
              &lt;artifactId&gt;xyz-xx-utils&lt;/artifactId&gt;
              &lt;version&gt;0.1-SNAPSHOT&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm.xyz&lt;/groupId&gt;
              &lt;artifactId&gt;xyz&lt;/artifactId&gt;
              &lt;version&gt;56.1&lt;/version&gt;
          &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>After applying the sed command I want it to look like:</p>
  
  <pre><code>&lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.company.xyz&lt;/groupId&gt;
              &lt;artifactId&gt;xyz-xx-utils&lt;/artifactId&gt;
              &lt;version&gt;NEW-VERSION&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm.xyz&lt;/groupId&gt;
              &lt;artifactId&gt;xyz&lt;/artifactId&gt;
              &lt;version&gt;56.1&lt;/version&gt;
          &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Here is what I have tried without any success:</p>
  
  <pre><code>newVersion="NEW-VERSION"
  
  sed -i "s/\(&lt;dependency&gt;\)\(&lt;groupId&gt;com.company.xyz&lt;/groupId&gt;\)\(&lt;artifactId&gt;.*\&lt;/artifactId&gt;\)\(&lt;version&gt;0.1-SNAPSHOT&lt;/version&gt;\)\(&lt;/dependency&gt;\)/\1\2\3$newVersion\5/" pom.xml
  </code></pre>
  
  <p>I was wondering if the reason why this does not work is because my text has multiple lines, so I researched a little bit but I did not understand the syntax used to work with multiple lines (some <code>N</code> thing).</p>
  
  <p>Btw, I am including this piece of code in a bash file that performs other operations, that is why I want to do this using sed or any other "tool" that is bash compatible.</p>