title: Modify the contents of a text file after a pattern has been found using sed/awk commands
body: <p>I tried to come up with a Tcl script, but I'm looking for something in sed/awk commands to make this faster.</p>
  
  <p>The file contains the following:</p>
  
  <pre><code>*Other text*
  .....
  .....
  .....
  SECTION LABELS {
  lab M1 0 0 0 0 3 1 bot
  lab M2 0 0 0 0 3 1 top
  } SECTION LABELS
  
  *Other text*
  ......
  ......
  ......
  SECTION LABELS {
  lab M1:NET 5207 12261 5207 12261 0 2 A
  lab M2:NET 6880 5370 6880 5370 0 2 B
  lab M1:NET 3454 5386 3454 5386 0 2 alpha
  lab M2:NET 3454 5386 3454 5386 0 2 beta
  } SECTION LABELS
  </code></pre>
  
  <p>I'm interested only in the lines containing within "SECTION LABELS". I'd like to:</p>
  
  <ul>
  <li>Change M1:NET to M1 and M2:NET to M2</li>
  <li>If the last element is A or B, change the number before A or B from 2 to 3</li>
  <li>If the last element is anything else, change the number (last but one) from 2 to 6</li>
  <li>If the numbers after lab M1:NET or lab M1 are 0 0 0 0, then I do not want to change anything.</li>
  <li>Rest of the contents of the file remain the same</li>
  </ul>
  
  <p>So the output looks like:</p>
  
  <pre><code>*Other text*
  .....
  .....
  .....
  SECTION LABELS {
  lab M1 0 0 0 0 3 1 bot
  lab M2 0 0 0 0 3 1 top
  } SECTION LABELS
  
  *Other text*
  ......
  ......
  ......
  SECTION LABELS {
  lab M1 5207 12261 5207 12261 0 3 A
  lab M2 6880 5370 6880 5370 0 3 B
  lab M1 3454 5386 3454 5386 0 6 alpha
  lab M2 3454 5386 3454 5386 0 6 beta
  } SECTION LABELS
  </code></pre>