title: rename script to adjust certain patterns within a filename in debian
body: <p>I'm currently a bit stuck, trying to adjust filenames within a folder tree if they have one or both of the following:</p>
  <ol>
  <li><p>Remove 'S00' - 'S99' -that part is to be cut out of the filename.
  <code>s/[sS](0[1-9]|[1-9][0-9])/</code> could do that I think</p>
  </li>
  <li><p>Any free standing double digits get an 'E' in front of them. Find <code>/\b([0-9]{2})\b/</code> and substitute <code>E$1</code> somehow</p>
  </li>
  </ol>
  <p>Example:
  any of these</p>
  <ul>
  <li><p>[lorem ipsum] dolor sit amet 07 [consetetur][1080p].mkv</p>
  </li>
  <li><p>[lorem ipsum] dolor sit amet S04 07 [consetetur][1080p].mkv</p>
  </li>
  <li><p>[lorem ipsum] dolor sit amet S04 E07 [consetetur][1080p].mkv</p>
  </li>
  </ul>
  <p>are changed to</p>
  <ul>
  <li>[lorem ipsum] dolor sit amet E07 [consetetur][1080p].mkv</li>
  </ul>
  <p>within their respective subfolders.</p>
  <p>Ultimate goal is to automate the process of renaming files as they appear (that latter bit I have to figure out once I'm done with this) so the kodi scraper can recognize episodes</p>
  <p>This is how far I got, as you can see, its still a mess as I've found this rename script here a while ago, but I don't know how to properly apply the regex, I just slapped it in</p>
  <pre><code>#!/bin/bash
  
  start_dir=&quot;//srv/MEDIA2/&quot;
  find &quot;$start_dir&quot; -name '*.*' -type f \
    |sort \
    |while read name; do 
       ((i++))
       mv -i &quot;$name&quot; \
  #remove season part
         &quot;$(printf 's/[sS](0[1-9]|[1-9][0-9])/' &quot;$(dirname &quot;$name&quot;)&quot; $((i)) &quot;$(basename &quot;$name&quot;)&quot;)&quot;
  #prepend E to free standing double digits
         &quot;$(printf 's/\b([0-9]{2})\b/' &quot;$(dirname &quot;$name&quot;)&quot; $((i)) &quot;$(basename &quot;$name&quot;)&quot;)&quot;
      
  done
  </code></pre>
  <p>Currently it returns</p>
  <pre><code>//home/user/./rnscript.sh: line 14: s/[sS](0[1-9]|[1-9][0-9])/: No such file or directory
  //home/user/./rnscript.sh: line 16: s([0-9]{2}/: No such file or directory
  </code></pre>
  <p>If anyone with knowhow in that area could help me out to get this running, it would be greatly appreciated.</p>