title: sh Break CSV files by value of column name matched while retaining header
body: <p>I have a directory with many CSV files from table exports</p>
  <p>tblA.csv</p>
  <pre><code>A,B,C
  1,1,1
  1,2,2
  2,2,2
  3,3,3
  </code></pre>
  <p>tblB.csv</p>
  <pre><code>C,D,A
  1,1,1
  1,2,2
  2,2,2
  3,3,3
  </code></pre>
  <p>In order to break the files I found this script</p>
  <pre><code>   awk -F, '
        NR== 1 { hdr = $0;next}
        {out = &quot;File&quot; $1 &quot;.csv&quot;}
        printed[$1]++&lt;1 {print hdr &gt;out}
        {print $0 &gt; out}
    ' tblA.csv 
  </code></pre>
  <p>that creates 3 files</p>
  <pre><code>A,B,C
  1,1,1
  1,2,2
  </code></pre>
  <pre><code>A,B,C
  2,2,2
  </code></pre>
  <pre><code>A,B,C
  3,3,3
  </code></pre>
  <p>Now for tblB.csv I still need to break the file by column A but that column is the 3rd not the 1st</p>
  <p>I can't figure out a way to pass the argument A have the it loop the header to find a column name that matches the argument I passed and then break the file using that column value. Or if that column name does not exist just skip the file.</p>