title: Combining columns of data from files matching a string in bash
body: <p>I have an unknown number of input files that all match a search string, let's say *.dat, and all have 2 columns of data and equal number of rows. In bash I need to take the 2nd column in each file and append it as a new column in a singular merged file. </p>
  
  <p>Eg:</p>
  
  <pre><code>&gt;&gt;cat File1.dat
  1   A
  2   B
  3   C
  &gt;&gt;cat File2.dat
  4   D
  5   E
  6   F
  &gt;&gt;cat combined.dat
  A   D
  B   E
  C   F
  </code></pre>
  
  <p>Here is the code I have tried, the approach I have gone for is to try to loop and append:</p>
  
  <pre><code>for filename in $(ls *.dat); do paste combined.dat &lt;(awk '{print $2}' $filename) &gt;&gt; combined.dat; done
  </code></pre>
  
  <p>The output format can be anything so long as its tab delimited, and the key is it must work on any number of input files up to...100 approx, where the number isn't known in advance. </p>