I'm trying to find the mean of several numbers in a file, which contains "< Overall >" on the line.
My code:
awk -v file=$file '{if ($1~"<Overall>") {rating+=$1; count++;}} {rating=rating/count; print file, rating;}}' $file | sed 's/<Overall>//'
I'm getting
awk: cmd. line:1: (FILENAME=[file] FNR=1) fatal: division by zero attempted
for every file. I can't see why count would be zero if the file does contain a line such as "< Overall >5"
EDIT: Sample from the (very large) input file, as requested:
<Author>RW53
<Content>Location! Location? view from room of nearby freeway
<Date>Dec 26, 2008
<No. Reader>-1
<No. Helpful>-1
<Overall>3
<Value>4
<Rooms>3
<Location>2
<Cleanliness>4
<Check in / front desk>3
<Service>-1
<Business service>-1
Expected output:
[filename] X
Where X is the average of all the lines containing < Overall >