Division by zero values in awk
<p>I am calculating an average score as follows:</p>

<pre><code>average_score=$(awk "BEGIN {printf \"%.2f\",${sum_of_score}/${number_of_lines}}")
</code></pre>

<p>where sum_of_scores is calculated as follows for each greped ID:</p>

<pre><code>sum_of_score=$(grep 271712:E1 M10.6.txt | awk '{s+=$5} END {print s}')

number_of_lines=$(grep 271712:E1 M10.6.txt | awk 'END{print FNR}')
</code></pre>

<p>However at times the value of sum_of_score and /or number_of_lines might be zero and hence I am getting an error:</p>

<pre><code>awk: BEGIN {printf "%.2f",/0}
awk:                       ^ unterminated regexp
awk: cmd. line:1: BEGIN {printf "%.2f",/0}
awk: cmd. line:1:                         ^ unexpected newline or end of string
</code></pre>

<p>How can I handle this error?</p>