title: How to add column n from all csv files and store in another csv file (with the header being the filename from which the column came from)?
body: <p>I have multiple .csv files and I want to extract a particular column from each. Lets say column 5. I want to take that column and add it to a csv file and append a new column onto it from each successive file. I am able to do this with the following code taken from someone else:</p>
  <pre><code>awk '{_[FNR]=(_[FNR] OFS $1)}END{for (i=1; i&lt;=FNR; i++) {sub(/^ /,&quot;&quot;,_[i]); print _[i]}}' input*.csv &gt; output.csv`
  </code></pre>
  <p>When I look at the output file I notice that the order in which the columns is added isn't sequential. As a result I was hoping to modify the code so that the header of the column is the filename from which the column came. How can I go about doing this?</p>
  <p>For example:
  input1.csv can be:</p>
  <pre><code>1,2,3,4,5
  6,7,8,9,10
  </code></pre>
  <p>input2.csv could be:</p>
  <pre><code>11,12,13,14,15
  16,17,18,19,20
  </code></pre>
  <p>And I would want the output.csv to be:</p>
  <pre><code>input1.csv, input2.csv
  5,15
  10,20
  </code></pre>
  <p>I hope this makes sense and thanks in advance.</p>