title: awk calculate average or zero
body: <p>I am calculating the average for a bunch of numbers in a bunch of text files like this:</p>
  
  <pre><code>grep '^num' file.$i | awk '{ sum += $2 } END { print sum / NR }'
  </code></pre>
  
  <p>But some times the file doesn't contain the pattern, in which cas I want the script to return zero. Any ideas of this slightly modified one-liner?</p>