Finding and replacing part of a line using variables in shell
<p>I have a file with several of lines with following format:</p>

<pre><code>#ABC-1X1X-XXX-8000-2AB-XXXX-3000                $(var1) $(var2) $(var3) $(var4)
</code></pre>

<p>After looking for <code>ABC-1X1X-XXX-8000-2AB-XXXX-3000</code> I need to remove <code>#</code> and update the file. Run few other commands and revert it back to original.</p>

<p>I tried below, but with this it removes <code>#</code> but also removes all of my other variable, remainder of the line.  I only want <code>#</code> removed from that line nothing else.  </p>

<pre><code>look_for=ABC-1X1X-XXX-8000-2AB-XXXX-3000
found=($(grep $look_for $file))
sed  -i "/$found/c \\$look_for" $file
</code></pre>

<p><strong>output:</strong></p>

<pre><code>ABC-1X1X-XXX-8000-2AB-XXXX-3000                    (missing all other variable)
</code></pre>