title: Replace a character in a section of a string in Bash
body: <p>I'm trying to replace <code>-</code> and <code>:</code> with <code>?</code> only in the middle(second) section delimited by <code>___</code> (3 underscore)</p>
  
  <p>input:</p>
  
  <pre><code>aaa___bb-bb:bbb___cc-cc:ccc
  d-d___d-ddd:d-d___e-e:e
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>aaa___bb?bb?bbb___cc-cc:ccc
  d-d___d?ddd?d?d___e-e:e
  </code></pre>
  
  <p>I tried below <code>sed</code> command but it only replaces the last occurrence of the <code>-:</code> in the middle section</p>
  
  <pre><code>echo "aaa___bb-bb:bbb___cc-cc:ccc
  d-d___d-ddd:d-d___e-e:e" | sed "s|\(___[^_]*\)[-:]\([^_]*___\)|\1?\2|g"
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>aaa___bb-bb?bbb___cc-cc:ccc
  d-d___d-ddd:d?d___e-e:e
  </code></pre>
  
  <p>I'm not restricted to only use <code>sed</code>. <code>awk</code>, <code>tr</code>, etc are fine too.</p>