I'm trying to extract the number range from two files.
$ cat file1.txt
chr1 69509
chr1 69511
chr1 71000
chr1 358112
chr1 586874
chr1 744200
. . .
$cat file2.txt
chr1 69091 70005
chr1 358070 358183
chr1 586842 586955
chr1 744195 744343
. . .
Desired output :
69509 chr1 69091 70005
69511 chr1 69091 70005
71000 out of range
358112 chr1 358070 358183
586874 chr1 586842 586955
744200 chr1 744195 744343
Below is my awk code.
awk 'NR==FNR{x[$1] = $2; next;}{for (i in x) {if (x[i] > $2 && x[i] < $3)print x[i], $1,$2,$3;else{print x[i], "out of range"}}}' file1.txt file2.txt
However, the output returned by this code contains only the data of the last NR.
For example,
744200 out of range
744200 out of range
744200 out of range
744200 chr1 744195 744343
I guess it is related to NR and FNR but I couldn't figure out how to do it.