title: Find and replace folder name in path
body: <p>In my Bash script, I have a variable that contains a path. Let say:</p>
  
  <pre><code>mypath=/a/b/c/d/e
  </code></pre>
  
  <p>I would like to be able and replace the name of the parent folder  of <code>c/d</code> by something else (let say <code>newB</code>), so as to get:</p>
  
  <pre><code>/a/newB/c/d/e
  </code></pre>
  
  <p>How can I do that?
  I've tried my best to combine cut, sed and awk but I'm getting awfully long commands without getting the desired result.</p>