Average of a skipping column of 5 using awk
I want to calculate the average of the 1st column of a text file, skipping lines divisible by 5. As an example, consider the following dataset.
1 2 3 4 5 6 7 8 9 10
For the above data, I can calculate the average of the entire column using awk
like
awk '{ sum += $1 } END { if (NR > 0) print sum / NR }' file
which prints the result 5.5
.
How can I extend this code to exclude lines divisible by 5 from the middle? In the example above, this will exclude the numbers 5
and from the mean 10
, resulting in a new mean 5
.
+3
source to share