title: merging 2 csv files using awk
body: <p>I have 3 CSV files:</p>
  
  <p>Base File(values initialised with 0)</p>
  
  <pre><code>steve tignor ash michael jose sam joshua
  0       0     0     0     0     0    0
  </code></pre>
  
  <p>File 1:</p>
  
  <pre><code>tignor michael  jose
  888      9       -2
  </code></pre>
  
  <p>File 2:</p>
  
  <pre><code>ash joshua
  77   66
  </code></pre>
  
  <p>Output I need:</p>
  
  <pre><code>      steve tignor ash michael jose sam joshua
  File1   0    888    0    9      -2   0     0
  File2   0     0     77   0       0   0     66
  </code></pre>
  
  <p>I tried with sorting the files first with awk and then merge with paste but as I have 1000+ columns and having 30 files it just did not work. </p>
  
  <p>Code:</p>
  
  <pre><code>awk -F"," 'NR==1{
    split($0,a,FS);asort(a);
    for(i=1;i&lt;=NF;i++)b[$i]=i
  } {
    for(i=1;i&lt;=NF;i++)printf("%s,",$(b[a[i]]));
    print x
  }' File1 &gt; 1.csv
  
  awk -F"," 'NR==1{
    split($0,a,FS);asort(a);
    for(i=1;i&lt;=NF;i++)b[$i]=i
  } {
    for(i=1;i&lt;=NF;i++)printf("%s,",$(b[a[i]]));
    print x
  }' File2 &gt; 2.csv
  
  paste -d"\n" 1.csv 2.csv &gt; merge.csv
  </code></pre>
  
  <p>Need some assistance here. Thanks in advance.</p>