I'm trying to add a column for each line together, and I do it like this:

awk '{s+=$2} END {print s}'

Now, when I have the final sum, s, I want to subtract the second column of the first line, like this:

awk '{s+=$2} {a= COLUMN 2 OF FIRST LINE } END {print s - a}'

How would I do that?

1 Answer 1


Just exclude the first line:

awk 'FNR>1{s+=$2};END{print s}'

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.