title: Is a /start/,/end/ range expression ever useful in awk?
body: <p>I've always contended that you should never use a range expression like:</p>
  
  <pre><code>/start/,/end/
  </code></pre>
  
  <p>in awk because although it makes the trivial case where you only want to print matching text including the start and end lines slightly briefer than the alternative*:</p>
  
  <pre><code>/start/{f=1} f{print; if (/end/) f=0}
  </code></pre>
  
  <p>when you want to tweak it even slightly to do anything else, it requires a complete re-write or results in duplicated or otherwise undesirable code. e.g. if you want to print the matching text excluding the range delimiters using the second form above you'd just tweak it to move the components around:</p>
  
  <pre><code>f{if (/end/) f=0; else print} /start/{f=1}
  </code></pre>
  
  <p>but if you started with <code>/start/,/end/</code> you'd need to abandon that approach in favor of what I just posted or you'd have to write something like:</p>
  
  <pre><code>/start/,/end/{ if (!/start|end/) print }
  </code></pre>
  
  <p>i.e. duplicate the conditions which is undesirable.</p>
  
  <p>Then I saw a question posted that required identifying the LAST <code>end</code> in a file and where a range expression was used in the solution and I thought it seemed like that might have some value (see <a href="https://stackoverflow.com/a/21145009/1745001">https://stackoverflow.com/a/21145009/1745001</a>).</p>
  
  <p>Now, though, I'm back to thinking that it's just not worth bothering with range expressions at all and a solution that doesn't use range expressions would have worked just as well for that case.</p>
  
  <p>So - does anyone have an example where a range expression actually adds noticeable value to a solution?</p>
  
  <p>*I used to use:</p>
  
  <pre><code>/start/{f=1} f; /end/{f=0}
  </code></pre>
  
  <p>but too many times I found I had to do something additional when <code>f</code> is true and <code>/end/</code> is found (or to put it another way ONLY do something when <code>/end/</code> is found IF <code>f</code> were true) so now I just try to stick to the slightly less brief but much more robust and extensible:</p>
  
  <pre><code>/start/{f=1} f{print; if (/end/) f=0}
  </code></pre>