I want to see just last sum here, but it shows me everything.

awk '{print sum += $1} END {print sum}' file.dat 

This is the output:

1.2 3.6 7.3 7.3 
3

1 Answer

Considering you want sums in file.dat added together and then print them out, the line should be:

awk '{sum +=$1} END {print sum}' file.dat 

Telling awk to print the sum every time you add a new value to sum makes it show each intermediate value, just as you have experienced.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy