title: Generic awk script to calculate average on any field through command line argument
body: <p>I want to write a generic awk script that can take as input a file and a field number (in that file) and give me the average value of that field in that file. I would use it something like this:</p>
  
  <pre><code>bash$ avg.awk 3 input.file
  22
  bash$ avg.awk 4 input.file
  2001
  </code></pre>
  
  <p>Of course, I can write the script if I know which field (e.g., $3) I am going to average beforehand. That would be something like this:</p>
  
  <pre><code>//{tot+=$3; count++}
  END{
      print tot/count;
  }
  </code></pre>
  
  <p>But I want to be able to change the field I want to average through a command line option. Is that possible? Thanks!</p>