title: Get Average of Found Numbers in Each File to Two Decimal Places
body: <p>I have a script that searches through all files in the directory and pulls the number next to the word <code>&lt;Overall&gt;</code>. I want to now get the average of the numbers from each file, and output the filename next to the average to two decimal places. I've gotten most of it to work except displaying the average. I should say I think it works, I'm not sure if it's pulling all of the instances in the file, and I'm definitely not sure if it's finding the average, it's hard to tell without the precision. I'm also sorting by the average at the end. I'm trying to use awk and bc to get the average, there's probably a better method.</p>
  
  <p><strong>What I have now:</strong></p>
  
  <pre><code>path="/home/Downloads/scores/*"
  
  (for i in $path
  do
      echo `basename $i .dat` `grep '&lt;Overall&gt;' &lt; $i |
      head -c 10 | tail -c 1 | awk '{total += $1} END {print total/NR}' | bc`
  done) | sort -g -k 2
  </code></pre>
  
  <p><strong>The output i get is:</strong></p>
  
  <pre><code>John 4
  Lucy 4
  Matt 5
  Sara 5
  </code></pre>
  
  <p>But it shouldn't be an integer and it should be to two decimal places.</p>
  
  <p>Additionally, the files I'm searching through look like this:</p>
  
  <pre><code>&lt;Student&gt;John
  &lt;Math&gt;2
  &lt;English&gt;3
  &lt;Overall&gt;5
  
  &lt;Student&gt;Richard
  &lt;Math&gt;2
  &lt;English&gt;2
  &lt;Overall&gt;4
  </code></pre>