I am really sorry for the confusion. Here I will try to make a new, more clear example:
file1
HTML Code:
1 1234 1240 abc
1 5678 9078 cdf
6 1223 4560 ogh
6 4567 100679 pog
8 2435 6789 kho
file2
HTML Code:
1 1235 col1
1 3456 col2
1 7890 col3
1 5679 col4
I need to match column1 in file2 to column1 if file2 first, then see if the number in column2 file2 is between the values of column2 and 3 of file1; and if so, ass column4 of file1 as an additional column to file2.
For example, in this file2, line1 - the number in column2 of file2, line1 is 1235, which is in the range of 1234 and 1240 of line1, columns 2 and 3 of file1; but it is also in the range of 1234 and 4560 of line3, columns 2 and 3 of file1. Because the first column of line 1, file2 matches the first column of line1, file1, the added value should be abc (and not ogh of line3, because the value of column1, line3, file1 does not match the value of column1, line1, file2). The output file should be like this:
HTML Code:
1 1235 col1 abc
1 3456 col2
1 7890 col3
1 5679 col4 cdf
What I meant by overlaping values in columns 2 and 3 of file1, is that the region covered by the first line (from 1234 to 1240) is also the part of the region in line3 (from 1223 to 4560), but they've got different values in column1 (1 and 6).
The values in columns 1 and 2 of file1 are sorted ascending. The values in columns1 and 2 of file2 are also sorted ascending.
Hope this is more clear and apologies for the confusion.
Many thanks for spending time on this!!!!
---------- Post updated at 03:57 PM ---------- Previous update was at 03:50 PM ----------
Sorry, I've noticed the typo in this paragraph. Here is the correct one:
For example, in this file2, line1 - the number in column2 of file2, line1 is 1235, which is in the range of 1234 and 1240 of line1, columns 2 and 3 of file1; but it is also in the range of 1223 and 4560 of line3, columns 2 and 3 of file1. Because the first column of line 1, file2 matches the first column of line1, file1, the added value should be abc (and not ogh of line3, because the value of column1, line3, file1 does not match the value of column1, line1, file2). The output file should be like this