title: How to replace date part in filename with current date
body: <p>How to replace only date part to current date of all files present in diretory in unix.</p>
  
  <p><strong>Folder path:</strong> <code>C:/shan</code></p>
  
  <p><strong>Sample files:</strong></p>
  
  <pre><code>CN_Apria_837p_20180924.txt  
  DN_Apria_837p_20150502.txt  
  GN_Apria_837p_20160502.txt  
  CH_Apria_837p_20170502.txt  
  CU_Apria_837p_20180502.txt  
  PN_Apria_837p_20140502.txt  
  CN_Apria_837p_20101502.txt  
  </code></pre>
  
  <p><strong>Desired result should be:</strong></p>
  
  <pre><code>CN_Apria_837p_20190502.txt  
  DN_Apria_837p_20190502.txt  
  GN_Apria_837p_20190502.txt  
  CH_Apria_837p_20190502.txt  
  CU_Apria_837p_20190502.txt  
  PN_Apria_837p_20190502.txt  
  CN_Apria_837p_20190502.txt
  </code></pre>
  
  <hr>
  
  <p><strong>Edit:</strong></p>
  
  <p>I'm completely new to unix sell scripting. I tried this below, however it's not working.</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  for i in ls $1 | grep -E '[0-9]{4}-[0-9]{2}-[0-9]{2}'
  do
    x=echo $i | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}'
    y=echo $i | sed "s/$x/$(date +%F)/g"
    mv $1/$i $1/$y 2&gt;/dev/null #incase if old date is same as current date
  done
  </code></pre>