title: How to extract last 2 characters before the extension of a filename in bash?
body: <p>What i would like to accomplish is to take a file name let's say <code>myfileRE.txt</code> and return the new file name of <code>myfile.txt</code>. The extra two characters will always be two characters and so what i tried to do was:</p>
  
  <pre><code>${filename%??.}
  </code></pre>
  
  <p>and my idea was "match the 2 characters that come right before the period and rip those characters out" ..unfortunately that just returned the entire filename. </p>
  
  <p>I ended up doing this:</p>
  
  <pre><code>${filename%??????}.txt
  </code></pre>
  
  <p>but that's not very friendly and there must be a cleaner way to do it. Any advice? Maybe something with regular expressions?</p>