title: Creating folder based on one file and files in those folders based on another file using AWK
body: <p>I have a fairly complex sub-task of:
  <strong>creating folders/directories based on one file</strong> (<code>PF.csv</code>) <strong>and creating files based on another file</strong> (<code>FC.py</code>) <strong>in those directories.</strong></p>
  
  <p><strong>The two input files to be used</strong></p>
  
  <p><em>Contents of the file</em> <code>PF.csv</code></p>
  
  <pre><code>#######Some description#######
  ,Rbig,Rsmall,Rmiddle,Lupper,Llower,
  DP 0,4.590,0.424,3.5,20,20,,,,,
  DP 1,2.949,0.192,1.831,8.508,17.3,,,,,
  DP 2,3.103,0.812,1.662,11.456,7.666,,,,,
  DP 3,2.418,0.058,1.876,6.295,9.032,,,,,
  </code></pre>
  
  <p><em>Contents of the file</em> <code>FC.py</code></p>
  
  <pre><code>###############Some description#############
  Lorem ipsum
  App.ActiveDocument.Spreadsheet.set('B2', '=5.0mm')#set Rbig here
  Lorem ipsum
  App.ActiveDocument.Spreadsheet.set('F2', '=9.0mm')#set Llower here
  </code></pre>
  
  <p><strong>Expected output:</strong>
  <a href="https://i.stack.imgur.com/5W9DX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5W9DX.png" alt="Expected output"></a>
  For each line of PF.csv, a directory and file inside it is to be created, named using the first column DPx (x = 0,1,2,...). Furthermore, the contents of the files are from FC.py, with changing certain lines using values from other columns (described below, how) of PF.csv.</p>
  
  <p><em>Contents of the file</em> <code>DP0/DP0.py</code></p>
  
  <pre><code>###############Some description############# 
  Lorem ipsum 
  App.ActiveDocument.Spreadsheet.set('B2', '=4.590mm')#set Rbig here
  Lorem ipsum
  App.ActiveDocument.Spreadsheet.set('F2', '=20mm')#set Llower here  
  </code></pre>
  
  <p><em>Contents of the file</em> <code>DP1/DP1.py</code></p>
  
  <pre><code>###############Some description############# 
  Lorem ipsum 
  App.ActiveDocument.Spreadsheet.set('B2', '=2.949mm')#set Rbig here
  Lorem ipsum
  App.ActiveDocument.Spreadsheet.set('F2', '=17.3mm')#set Llower here  
  </code></pre>
  
  <p><em>Contents of the file</em> <code>DP2/DP2.py</code></p>
  
  <pre><code>###############Some description############# 
  Lorem ipsum 
  App.ActiveDocument.Spreadsheet.set('B2', '=3.103mm')#set Rbig here
  Lorem ipsum
  App.ActiveDocument.Spreadsheet.set('F2', '=7.666mm')#set Llower here  
  </code></pre>
  
  <p><em>Contents of the file</em> <code>DP3/DP3.py</code></p>
  
  <pre><code>###############Some description############# 
  Lorem ipsum 
  App.ActiveDocument.Spreadsheet.set('B2', '=2.412mm')#set Rbig here
  Lorem ipsum
  App.ActiveDocument.Spreadsheet.set('F2', '=9.032mm')#set Llower here  
  </code></pre>
  
  <p><strong>My code</strong></p>
  
  <pre><code>awk 'BEGIN {FS = ",";}
   {
    if ($1 ~ "DP")
      {Rbig = $2; Llower = $6;    #values are assigned from each line read from PF.csv
      gsub(" ",""); system("mkdir "$1); filename=$1"/"$1".txt";    #empty space is pruned from first column ('DP x', x=0,1,2,...) and folder with file is created with the name using system() and filename  
      {(getline &lt; "FC.py");    #FC.py is read, processing further FC.py only, taking the folders and values assigned using the previous codes for file PF.csv only.
        {
          if ($0 ~ "#set Rbig here")     #if it finds a line with this, it assigns the value of Rbig, taken from PF.csv just before.
            {gsub("5.0mm",Rbig"mm"); print &gt;&gt; filename;}
          else if ($0 ~ "#set Llower here")    #simlarly assigns Llower like previous two line codes
            {gsub("9.0mm",Ll"mm"); print &gt;&gt; filename;}
          else
            {print &gt;&gt; filename;}
        }; close(filename)
      }
      }
    }
  ' PF.csv
  </code></pre>
  
  <p><strong>Output of my code (not desired)</strong>
  The folders are created but only the file <code>DP2/DP2.py</code> with the line <code>App.ActiveDocument.Spreadsheet.set('B2', '=3.103mm')#set Rbig here</code> is created.</p>
  
  <p>I'm sure it's possible but have not succeeded due to lack of understanding. Please explain in your answers where the problem is and how did you overcome it using <code>AWK</code>.</p>
  
  <blockquote>
    <p>PS: I can only accept answers using only AWK as it's part of a bigger
    workflow, but feel free to add other solutions, if possible using
    shell scripts. Also, the script should be called using a shell script or typed directly in terminal in Linux/Mac.</p>
  </blockquote>