3

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?

6

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)).

| improve this answer | |
2

Use this reference for joinig the two files: Question 7392204

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

| improve this answer | |

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.