 <p>This is what you want:</p> <pre><code>echo "$line" | sed -E 's/(QA.|DEV.)(.*)/&lt;!-- \1\2 --&gt;/' </code></pre> <p>The <strong>first group</strong> could be prefixed by <code>QA</code> or <code>DEV</code> , use the <code>|</code> <em>or</em> operator.</p> <p>A <em>few</em> <strong>alternatives</strong>:</p> <pre><code>$ echo "QA2 ABCDEFGHI"|sed -E 's/(.*)/&lt;!-- \1 --&gt;/' &lt;!-- QA2 ABCDEFGHI --&gt; $ echo "QA2 ABCDEFGHI"|awk '{print "&lt;!-- "$0"--&gt;"}' &lt;!-- QA2 ABCDEFGHI--&gt; </code></pre>