title: Match a pattern within a block of text bounded by two different patterns
body: <p>Is there a way to match a pattern within a block of text whose boundaries are two unique patterns on different lines? By that I mean:</p>
  
  <pre><code>/*some comment*/
  void something_patternWord1()
  {
     some_code;
     some_code;
     some_code_patternWord3;
     some_code;
  }
  /*some comment patternWord2
  </code></pre>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>/*some comment*/
  void something_patternWord1()
  {
     some_code;
     some_code;
     new_line_of_some_code;   //after performing sed command
     some_code_patternWord3;
     some_code;
  }
  /*some comment patternWord2
  </code></pre>
  
  <p><strong>What I've tried:</strong></p>
  
  <pre><code>sed '/patternWord1/,/patternWord2/{/patternWord3/i new_line_of_some_code;}' inputFile &gt; outputFile
  </code></pre>
  
  <p>The above command doesn't seem to be working. </p>
  
  <p>Ultimately, what I'm trying to achieve is using <code>bash</code> script, read in some stuff from <code>.csv</code> file, and if the word read in is <code>someWord</code> then search for a block of text bounded by <code>patternWord1</code> and <code>patternWord2</code>,  match <code>patternWord3</code> within that block of text and insert some code above it.</p>
  
  <p>I have many <code>.cpp</code> files with many different functions and therefore many combinations of different <code>patternWord1</code> and <code>patternWord2</code>.</p>
  
  <p>Is what I'm trying to do even possible with <code>sed</code>, and is <code>sed</code> the best tool for something like this?</p>
  
  <p>Perhaps another approach: would it be possible for me to use <code>if-then</code> statements in <code>bash</code> while having the script read in a <code>.cpp</code> file, and <em>then</em> use the <code>sed</code> command to match for <code>patternWord3</code> and insert a new line of code?</p>
  
  <p>If you could help me out with <code>sed</code> that would be great, but also I'm open to other suggestions as well if it make more sense/it is more efficient. Thank you in advance.</p>