Average of certain range using awk

Hello, I am currently trying to use awk in order to calculate the average of values that are greater than 500 in column 1. What I have so far is:

awk ‘$1 > 500 {sum+=$1} END {print sum/NR}’

My issue is that I am not sure how to specify to divide the sum of values greater than 500 by the number of values greater than 500, since NR includes all the records.

This is for an intro level course.

awk ‘$1 > 500 {sum+=$1; num++} END {print sum/num}’
3 Likes

Thank you!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.