title: Replacing first occurence except comments using sed
body: <p>I have a text file of the form:</p>
  
  <pre><code>a = 1
  #b = [2,3]
  c = 4
  d = [5,6]
  e = [7,8]
  </code></pre>
  
  <p>I want to replace the pattern inside the brackets (and the brackets) with a number, but ignore matches in the comments, preferably using sed.</p>
  
  <p>For files with exactly one matching line, I've used</p>
  
  <pre><code>sed -i "/^#/!s/\[.*\]/9/" myfile
  </code></pre>
  
  <p>How can this be modified to replace only the first match if there are more?</p>