title: calculating average over many files
body: <p>I would like to calculate average value for data in multiple files: (about 10 files). Lets say I have file1.dat, file2.dat, file3.dat and ... file10.dat. 
  Each file contains two columns. The "first column is line number" and the "<strong>second column is the data</strong>". In total I have 1800 lines in a file. The pattern of the data is shown below:</p>
  
  <pre><code>    1.00   0.659
      2.00   0.608
      3.00   0.578
      4.00   0.557
      5.00   0.543
      6.00   0.527
      7.00   0.514
      8.00   0.502
      9.00   0.489
      . 
      .
      .
   1800.00   0.480
  </code></pre>
  
  <p>I want to calculate average for <strong>data</strong> according to line numbers from each file. That means, I want to find average for the all first line data from file1, file2... and file10 and write in <em>new file</em>. Then average for the all second line data from file1, file2... and file10 and write in the same <em>new file</em>.</p>
  
  <p>That <em>new file</em> supposed to have the format as below. For example; </p>
  
  <pre><code>    1.00   0.112
      2.00   0.324
      3.00   0.887
      . 
      .
  </code></pre>
  
  <p>Where the first column is the line number and the second column is the average values for data. I shall explain bit detail for clarity purpose. In the above example, <strong>0.112</strong> is the average for all data in first line from each file. And <strong>0.324</strong> is the average value for all data in second line from each file.</p>
  
  <p>What I want is the code which can accomplish this calculation.</p>
  
  <p>I have tried with perl for openning a file. But lost when trying to figure out to convert the idea into code. The perl that I wrote is as below</p>
  
  <pre><code>#!/usr/bin/perl -w
  
  open (FILE, "file1.dat") or die $!;
  while (&lt;FILE&gt;) {
  chomp;
  print "$_\n";
  }
  close (FILE);
  </code></pre>
  
  <p>Thanks in advance. </p>