title: How to merge n tab separated files by unique first 3 columns and average 4th columns?
body: <p>I am stuck finding a simpler way to merge and average n (n&lt;10) tab-separated files, then using <code>join</code> on two of them, then <code>awk</code> to delete duplicate columns, and then finally ending up with n columns to be averaged. I am happy to do some more "homework" if you can recommend suitable sources to read about. Thanks!</p>
  
  <p>Say I have <code>N</code> tables of the format <code>tableN1</code>:</p>
  
  <pre><code>c1 650 651 3e-07
  c2 550 440 2e-04
  
  tableN2
  
  c1 650 651 2.8e-07
  c2 550 440 2.1e-04
  
  ..
  
  tableNi
  
  c1 650 651 2.9e-07
  c2 550 440 2.2e-04
  </code></pre>
  
  <p>The only way I would handle this is using (which can't be the right way):</p>
  
  <pre><code>join -j1 tableN1 tableN2 | awk '{ print $1,$2,$3,$4,$7 }' | join - tableN3 | awk '{ print $1,$2,$3,$4,$5,$8 }' | ...
  
  | awk -v N=$N '{ print $1,$2,$3,($4+$5+...,$N+4)/N}
  </code></pre>