title: Using AWK to break out pieces of a single file into multiple files, but I need further direction
body: <p>I am still very new to this type of task, but I have exhausted my resources and thus am reaching out for a helping hand.</p>
  
  <p>I have a single file composed of concatenated files. I am able to use the exact line of code below to break the files apart:</p>
  
  <p><code>awk "/PATTERN/{x="F"++i;}{print &gt; x;}" sourceFile</code></p>
  
  <p>BUT - </p>
  
  <ol>
  <li><p>If possible I would like to dictate a directory for the output files - the above script writes the output files to the "sourceFile" directory, I would want these files to be dropped in some sort of temp directory.</p></li>
  <li><p>It would be extremely helpful if the output files could retain their
  "sourceFile" name with perhaps a counter on the end while
  maintaining a .txt file type - i.e. sourceFile1.txt,
  sourceFile2.txt, etc.</p></li>
  </ol>
  
  <p>I have tried the following to retain the sourceFile name, but it was unsuccessful:</p>
  
  <pre><code>set F=sourceFile
  awk "/PATTERN/{x="F"++i;}{print &gt; x;}" sourceFile
  </code></pre>
  
  <p>I apologize if this is rudimentary, but this could greatly aid in daily tasks - so I was hoping someone could help. Thank you in advance!</p>