title: Averaging lines without awk using bash
body: <p>I'm just starting to use bash, and I'm having some difficulties with bash arithmetic. Lets say I have a some cities with three temperatures, and I'd like to average the temperatures without using the awk command. How can I do this? I've done it with awk, but I'm practicing with different techniques.</p>
  
  <pre><code># cityTemp.txt with four cities, three day's temperatures
  Toronto 20 25 30
  Miami 80 80 110
  London 40 20 60
  New York 5 10 15 
  </code></pre>
  
  <p>Lets say I'm trying to write a script to output:</p>
  
  <pre><code>25 Toronto
  90 Miami
  40 London
  10 New York
  </code></pre>
  
  <p>I've already done this with some piping and the awk command, but I'm having problems doing this without using awk.</p>
  
  <p>Again, I'm new to this. I tried a for loop, but I didn't really know what I was doing.</p>
  
  <p>---edit 1:</p>
  
  <p>Benjamin W. I'm editing again, but right now I'm playing with a loop:</p>
  
  <pre><code>#!/bin/bash
  
  for i in $(cat $1)
  do
      echo "i is: ${i}"
  done &lt; $1
  </code></pre>
  
  <p>This is, maybe obviously, just printing every field from cityTemp.txt one at a time. </p>
  
  <p>---edit 2:</p>
  
  <p>This was my ending attempt</p>
  
  <pre><code>while read -a rows
  do
      total=0
      sum=0
      for i in "${rows[@]}"
      do
          sum=`expr $sum + $i`
          total=`expr $total + 1`
      done
      average=`expr $sum / $total`
      Output = ${average}
  done &lt; $1
  echo ${averages}
  </code></pre>