Hi everyone,

I have two unequal data sets.

    A data set
    V1     V2          V3
    6	42721754	42721769
    6	42721757	42721772
    6	42721760	42721775
    6	42721763	42721778
    6	42721766	42721781
    6	42721769	42721784
    6	42721772	42721787
    6	42721775	42721790

    B data set
    V2            	AF
    42721757	0.003067485
    42721760	0.006134969
    42721763	0.006134969
    42721766	0.003067485
    42721769	0.006134969
    42721772	0.006134969
    42721775	0.003067485
    42721778	0.006134969
    42721781	0.003067485
    42721784	0.003067485
    42721787	0.009202454
    42721790	0.009202454

I want to check if  the value of `V2` in `B data set`  falls between the values of `V2` and `V3` of `A data set`. And when its true, I want value of `AF` in `B data set` to be added as a new column in `A dataset`. 
There are two important points.
1. `B data set` is 80 rows while `A data set` is 6000 rows.
2. value of `V2` in `B` may be repeated,  which shouldn't get thrown out in final output.

an urgent help with be appreciated.

Thanks,

Hey, you can try the idea of Rashedul; however, using *BEDTools*, you may encounter issues with the sorting of the regions and also the fact that you implied how the co-ordinates in B can be repeated.

Here is a solution in trusty AWK:

    cat A.txt 
    V1	V2	V3
    6	42721754	42721769
    6	42721757	42721772
    6	42721760	42721775
    6	42721763	42721778
    6	42721766	42721781
    6	42721769	42721784
    6	42721772	42721787
    6	42721775	42721790

    cat B.txt 
    V2	AF
    42721757	0.003067485
    42721760	0.006134969
    42721763	0.006134969
    42721766	0.003067485
    42721769	0.006134969
    42721772	0.006134969
    42721775	0.003067485
    42721778	0.006134969
    42721781	0.003067485
    42721784	0.003067485
    42721787	0.009202454
    42721790	0.009202454

    awk 'FNR==NR \
      {if (NR>1) {arr[$1]=$2}; next} \
      {if (FNR>1) \
        {for (pos in arr) \
          if ((pos > $2) && (pos < $3)) \
            print $0"\t"arr[pos]}}' FS='\t' B.txt FS='\t' A.txt 
    6	42721754	42721769	0.003067485
    6	42721754	42721769	0.006134969
    6	42721754	42721769	0.006134969
    6	42721754	42721769	0.003067485
    6	42721757	42721772	0.006134969
    6	42721757	42721772	0.006134969
    6	42721757	42721772	0.003067485
    6	42721757	42721772	0.006134969
    6	42721760	42721775	0.006134969
    6	42721760	42721775	0.003067485
    6	42721760	42721775	0.006134969
    6	42721760	42721775	0.006134969
    6	42721763	42721778	0.003067485
    6	42721763	42721778	0.006134969
    6	42721763	42721778	0.006134969
    6	42721763	42721778	0.003067485
    6	42721766	42721781	0.006134969
    6	42721766	42721781	0.006134969
    6	42721766	42721781	0.003067485
    6	42721766	42721781	0.006134969
    6	42721769	42721784	0.006134969
    6	42721769	42721784	0.003067485
    6	42721769	42721784	0.006134969
    6	42721769	42721784	0.003067485
    6	42721772	42721787	0.003067485
    6	42721772	42721787	0.006134969
    6	42721772	42721787	0.003067485
    6	42721772	42721787	0.003067485
    6	42721775	42721790	0.006134969
    6	42721775	42721790	0.003067485
    6	42721775	42721790	0.003067485
    6	42721775	42721790	0.009202454

This assumes that the files are tab-delimited and that they genuinely have the headers that you imply they have (the code instructs to skip the first line of each). If the files are not tab-delimited, then modify the values set for `FS`.

Also, it assumes that you want to match ***between*** the regions specified in *A.txt*, so, '*less than*' or '*greater than*', but not '*less than or equal to*' or '*greater than or equal to*'. Modify `>` and `<` in the code to suit your needs.

Kevin