title: Renaming multiple directories while keeping a part in the middle with varying suffix
body: <p>I'm trying to change the name of multiple directories using bash, the names being structures like the following:</p>
  <blockquote>
  <p>DRMAD_CA-12__MRBK01_237a8430    DRMAD_CA-17__MRBK10_766c3396<br />
  DRMAD_CA-103__MRBK100_c27a6c1c</p>
  </blockquote>
  <p>The goal is the to keep the MRBK as well as the number following directly after it (<code>MRBK###</code>), but to get rid of of the rest. The pattern of the prefix is always the same (<code>DRMAD_CA-###__</code>), while the suffix is '<code>_</code>' followed by a combination of exactly 8 letters and digits. Tried <code>sed</code>, but can't seem to figure out the right pattern.</p>
  <p>Seeing other posts on Stackoverflow, I've tired variations of</p>
  <pre class="lang-sh prettyprint-override"><code>ls | while read file; do new=$( echo $file | sed 's/[^0-9]*\([^ ]*\)[^.]*\(\..*\)*MRBK\1\2/' ) mv &quot;$file&quot; &quot;$new&quot; done
  </code></pre>
  <p>But since I don't really understand the syntax of sed, it doesn't produce a usable result.</p>