Hi,
Using awk, I am trying to append the comment(s) of file2 at the end of file1 if:
- field1 of file1 is equal to field1 of file2
AND
- field2 of file1 is ≥ field2 of file2 and ≤ field3 in file2
file1.tab (NF is constant):
Code:
1 20 value1
4 73 value2
file2.tab (NF is variable):
Code:
1 10 30 commentA1 commentA2
2 50 89 commentB1
4 55 90 commentC1
output:
Code:
1 20 value1 commentA1 commentA2
4 73 value2 commentC1
I can (kind of) output the first condition (i.e. if $1 file1 = $2 file2), but
don't see how to do deal with the second condition:
Code:
gawk 'BEGIN{FS="\t"}NR==FNR{a[$1]=$0; next}{print $0 FS a[$1]}' file2 file1
which produces:
Code:
1 20 value1 1 10 30 commentA1 commentA2
4 73 value2 4 55 90 commentC1