0
A  1  15  4
B  2  14  5
C  3  13  6
D  4  12  4

I would like to add columns 2 (1+2+3+4) and 3 (15+14+13+12) and eventually add them together, while ignoring columns 1 and 4. How can I accomplish this?

2 Answers 2

3

sum columns 1, 3 and 1+3

awk 'BEGIN {FS = " "} ; {sum+=$2} {sum2+=$3} END {print sum, sum2, sum+sum2}'  file
Sign up to request clarification or add additional context in comments.

Comments

0

You can try below:

awk 'BEGIN {FS = " "} ; {sum+=$2} {sum1+=$3} END {print sum sum1}' file.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.