Reputation: 75
I have an awk line to calculate an average that works fine but when I put it into an if statement, I get a syntax error referring to the part with "END". I want to calculate the average only if certain conditions are fulfilled.
Line for calculating average that works:
awk '{ sum += $2; n++ } END { if (n > 0) print sum / n; }' input.txt
Line for calculating average after if statement which doesn't work:
awk '{if ( $1 > 5 ) { {sum += $2; n++} END { if (n > 0) print sum / n; }}}' input.txt
I would like to know where the error is, changing the type and number of brackets did not help.
Upvotes: 0
Views: 279