title: Excel formula / AWK equivalent
body: <p>I'm trying to automate many calculations from several files. I've done it with Excel and have the formulas needed.</p>
  
  <p>My input <code>Input.txt</code> is </p>
  
  <pre><code>Start   End
  0   0
  1793    3233
  3147    4045
  4085    6751
  28077   29336
  29258   31431
  29304   30010
  31528   42846
  </code></pre>
  
  <p>What I'm trying to get is the <code>Size</code> from <code>Start</code> to <code>End</code> and substract the possible overlaps: e.g. in row 4, the <code>Start</code> (3147) overlaps with the <code>End</code> of row 3 (3233), so the effective <code>Size</code> is only 813, due to that overlap. </p>
  
  <p>Row 8 in this example (29304 - 30010) is not only overlapped but is contained by row 7 (29258 - 31431) so it doesn't add any effective size. </p>
  
  <p>My desired output <code>Out.txt</code> is:</p>
  
  <pre><code>Start   End Size    No-Negatives    Overlap No-Negatives
  0   0   0   0   0   0
  1793    3233    1442    1442    -1792   0
  3147    4045    813 813 87  87
  4085    6751    2668    2668    -39 0
  28077   29336   1261    1261    -21325  0
  29258   31431   2096    2096    79  79
  29304   30010   -1420   0   2128    2128
  31528   42846   11320   11320   -96 0
  </code></pre>
  
  <p>The final number I need, which I can easily calculate once I have the complete table is the sum of <code>$4</code> which tells me the effective total size.</p>
  
  <p>I've done it in Excel adding the original <code>Input.txt</code> to columns A and B and used the next formulas to obtain columns <code>$3</code> to <code>$6</code> of <code>Out.txt</code> (Size, No-negatives, Overlap, No-negatives) </p>
  
  <p><code>$3</code> (C): <code>=B3-(A3+F3)+2</code></p>
  
  <p><code>$4</code> (D): <code>=IF(C3&gt;0,C3,0)</code></p>
  
  <p><code>$5</code> (E): <code>=B2-A3+1</code></p>
  
  <p><code>$6</code> (F): <code>=IF(E3&gt;0,E3,0)</code></p>
  
  <p>Is there a <code>bash</code>, <code>awk</code>, or any script with which I can obtain columns `` to process many files?</p>
  
  <p>Thank you in advance.</p>