I would like to write a bash code in order two compare different files in the following way.
When the value of the first five column are equal in both file, sum the value of the remaining column in the two different file together(e.g. colum6file1+colum6file2,etc). When they are different just keep both of the different line in the new file.
Notice that i cannot compare line by line because a line at the beginning of the first file can have the same four column value of a line at the end of the second file.
Hope this is clear,
Thanks.
File1:
118 2 AA 4.25 30.25 1
119 2 AA 4.50 30.25 2
120 2 AA 4.75 30.25 3
121 2 AA 5.00 30.25 4
122 2 AA 5.25 30.25 5
123 2 AA 5.50 30.25 6
124 2 AA 5.75 30.25 7
125 2 AA 6.00 30.25 8
126 2 AA 6.25 30.25 9
File2:
179 1 BB 19.75 30.00 1
180 1 BB 19.75 30.00 2
230 1 BB 32.25 30.00 3
231 1 BB 32.50 30.00 4
232 1 BB 32.75 30.00 5
118 2 AA 4.25 30.25 6
119 2 AA 4.50 30.25 7
120 2 AA 5.00 30.25 8
121 2 AA 5.00 30.25 9
Output:
118 2 AA 4.25 30.25 7
119 2 AA 4.50 30.25 9
120 2 AA 4.75 30.25 11
121 2 AA 5.00 30.25 13
122 2 AA 5.25 30.25 5
123 2 AA 5.50 30.25 6
124 2 AA 5.75 30.25 7
125 2 AA 6.00 30.25 8
126 2 AA 6.25 30.25 9
179 1 BB 19.50 30.00 1
180 1 BB 19.75 30.00 2
230 1 BB 32.25 30.00 3
231 1 BB 32.50 30.00 4
232 1 BB 32.75 30.00 5
This can likely be minimized, but here’s a rough cut at a solution to what I think is the question: