title: Using gawk to Replace a Pattern of Text with the Contents of a File Whose Filename is Inside the Text
body: <p>I am trying to replace text inside a text file according to a certain criteria. </p>
  
  <p>For example, if I have three text files, with outer.txt containing:</p>
  
  <pre><code>   Blah Blah Blah
     INCLUDE inner1.txt
     Etcetera Etcetera
     INCLUDE inner2.txt
     end of file
  </code></pre>
  
  <p>And inner1.txt containing: </p>
  
  <pre><code>  contents of inner1
  </code></pre>
  
  <p>And inner2.txt containing:</p>
  
  <pre><code>  contents of inner2
  </code></pre>
  
  <p>At the end of the replacement, the outer.txt file would look like:</p>
  
  <pre><code>    Blah Blah Blah
      contents of inner1
      Etcetera Etcetera
      contents of inner2
      end of file
  </code></pre>
  
  <p>The overall pattern would be that for every instance of the word "INCLUDE", replace that entire line with the contents of the file whose filename immediately follows that instance of "INCLUDE", which in one case would be inner1.txt and in the second case would be inner2.txt.</p>
  
  <p>Put more simply, is it possible for gawk to be able to determine which text file is to be embedded into the outer text file based on the very contents to be replaced in the outer text file?</p>