Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have two files A and B with the same number of lines. Each of them has multiple columns. I want to add field 6 in file A with field 3 in file B for each line. e.g.:

file A:

2769 RUT10EKl3fY 0 0.00483891 1352626500270 2 
2773 0XbIZqg4v7w 0 0.00360106 1352626851193 3
2777 j1tuJt5IyUw 0 0.00460544 1352627235337 4

file B:

2769 RUT10EKl3fY 1
2773 0XbIZqg4v7w 8
2777 j1tuJt5IyUw 9

Result (1+2, 3+8, 9+4):

3
11
13

How can I achieve this?

share|improve this question

2 Answers 2

Do this:

$ paste A B | awk '{ print $6 + $9 }'

(assuming you really mean the 6th field of file A, and the 3rd of file B (6 + 3 = 9)).

share|improve this answer

Use this reference for joinig the two files: Question 7392204

You can add two numbers by typing expr 1 + 2 in bash.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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