Unix: Remove date from filename using sed without modifying existing one
<p>I have a legacy code which transmits the file only if it has date within the command. But client transmission doesnt want date to be appended to filename. legacy code cannot be modified since many other transmision depends on it. So my requirement is i want to have date parameter in the command but again the same has to be removed using a single command. </p>

<p>Condition in legacy code:</p>

<pre><code> grep '\`date' $COMMAND
</code></pre>

<p>Note: COMMAND will contain the complete command defined below and not the filename (not CMD output).</p>

<p>So ideally my command should have `date added. I added a command like this below.</p>

<pre><code>CMD=`echo prefix_filename.txt | sed 's/^prefix_//'`_`date +%m%d%Y`
</code></pre>

<p>The above command is used to remove prefix_ and send filename. Here i get output as filename.txt_09232016. Since legacy code logic only checks if command has `date in it, i added it. Is there a way to remove the date again in the same command so that my output will be filename.txt</p>

<p>Current output:</p>

<pre><code>filename.txt_09232016
</code></pre>

<p>Expected output:</p>

<pre><code> filename.txt
</code></pre>