title: Inserting text below and above a matched pattern
body: <p>First of all, thanks for such a wonderful community we have!! I have always been benefited by the great knowledge shared here on stackoverflow.</p>
  
  <p>Coming to the problem I was facing:</p>
  
  <p>I have a bunch of files(about 200) In those files I wanted to search for a pattern(multi-line) and if the pattern matches, I want to add some text above and below the pattern.</p>
  
  <p>E.g</p>
  
  <p>File1.cpp</p>
  
  <pre><code>#ifndef FILE1_H
  #define FILE1_H
  
  #ifndef PARENT1_H
  #include "Parent1.h"
  #endif
  
  #ifndef SIBLING_H
  #include "Sibling.h"
  #endif
  
  #ifndef PARENT2_H
  #include "Parent2.h"
  #endif
  
  class File1
  {
  };
  
  #endif    
  </code></pre>
  
  <p>In this file I wanted to add <code>#ifndef NOPARENT</code> above <code>#ifndef PARENT1_H</code> and <code>#endif</code> below <code>#endif</code> which is right below <code>Parent1.h</code>.</p>
  
  <p>I want to do the same thing for <code>#ifndef PARENT2_H</code></p>
  
  <p>So the output will look like:</p>
  
  <pre><code>#ifndef FILE1_H
  #define FILE1_H
  
  #ifndef NOPARENT
  #ifndef PARENT1_H
  #include "Parent1.h"
  #endif
  #endif
  
  
  #ifndef SIBLING_H
  #include "Sibling.h"
  #endif
  
  #ifndef NOPARENT
  #ifndef PARENT2_H
  #include "Parent2.h"
  #endif
  #endif
  
  class File1
  {
  };
  
  #endif    
  </code></pre>
  
  <p>I have a list of such matches. For e.g here I was searching for PARENT1_H, PARENT2_H etc but I have more like GRANDPARENT1_H, GREATGRANDPARENT_H etc</p>
  
  <p>So essentially, the approach I was thinking is, search for the input symbols(<code>PARENT1_H</code> etc) in those files and if a match is found, add the text(<code>#ifndef NOPARENT</code>) above and <code>#endif</code> below.</p>
  
  <p>Input symbols are many and so are the files in which to replace.</p>
  
  <p>Can anyone please help me with a script which does this using sed/awk/perl. Or any other language/script(bash etc) would also be great!</p>
  
  <p>I am novice user of sed/awk/perl so could use the help</p>
  
  <p>Thanks a lot :-)</p>
  
  <p>Best Regards,
  Marc</p>