I have a file (let say file B) like this:
File B:
A1 3 5
A1 7 9
A2 2 5
A3 1 3
The first column defines a filename and the other two define a range in that specific file. In the same directory, I have also three more files (File A1, A2 and A3). Here is 10 sample lines from each file:
File A1: File A2: File A3:
1 0.6 1 0.2 1 0.1
2 0.04 2 0.1 2 0.2
3 0.4 3 0.2 3 0.5
4 0.5 4 0.4 4 0.3
5 0.009 5 0.2 5 0.7
6 0.2 6 0.3 6 0.3
7 0.3 7 0.8 7 0.3
8 0.2 8 0.1 8 0.2
9 0.15 9 0.9 9 0.8
10 0.1 10 0.4 10 0.1
I need to add a new column to file B, which in each line gives the sum of values of column two in the defined range and file. For example, file B row 1 means that calculate the sum of values of line 3 to 5 in column two of file A1. The desired output is something like this:
File B:
A1 3 5 0.909
A1 7 9 0.65
A2 2 5 0.9
A3 1 3 0.8
All files are in tabular text format. How can I perform this task? I have access to bash (ubuntu 14.04) and R but not an expert bash or R programmer. Any help would be greatly appreciated. Thanks in advance