title: How to add line before match within given line range/patterns using sed?
body: <p>I want to do a basic <code>sed</code>-line insertion but withing a given line range.</p>
  
  <p>Using given sample file <code>sample.txt</code>:</p>
  
  <pre><code>foo
  tomato
  apple
  bar
  START_MARKER
  tomato
  apple
  kiwifruit
  pineapple
  strawberry
  
  END_MARKER
  
  apple
  qux
  </code></pre>
  
  <p>I want to add a line (say "_____new_line_____") before any line between "START_MARKER" and "END_MARKER" that contains "apple".
  My sample would then become:</p>
  
  <pre><code>foo
  tomato
  apple
  bar
  START_MARKER
  tomato
  _____new_line_____
  apple
  kiwifruit
  _____new_line_____
  pineapple
  strawberry
  
  END_MARKER
  
  apple
  qux
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>sed '/^START_MARKER$/,/^END_MARKER$/ /apple/i _____new_line_____' sample.txt
  </code></pre>
  
  <p>But I get:</p>
  
  <blockquote>
    <p>sed: -e expression #1, char 33: unknown command: `/'</p>
  </blockquote>
  
  <p>Also tried:</p>
  
  <pre><code>sed '/^START_MARKER$/,/^END_MARKER$/ {/apple/i _____new_line_____}' sample.txt
  </code></pre>
  
  <p>But I get:</p>
  
  <blockquote>
    <p>sed: -e expression #1, char 0: unmatched `{'</p>
  </blockquote>
  
  <p>If I wanted to add a "_____new_line_____" line before all line containing "apple" (not using START_MARKER and END_MARKER) the following would work:</p>
  
  <pre><code>sed '/apple/i _____new_line_____' sample.txt
  </code></pre>
  
  <p>I am missing something to chain/combine the /start/,/end/ pattern selection with my //i add-line-operation.</p>