Values between ranges

Hi,

I have two files

file1

chr1_22450_22500
chr2_12300_12350
chr1_34500_34550

file2

11000_13000
15000_19000
33000_44000

If the file 1 ranges fall between file2 ranges then assign the value of file2 in column 2 to file1

output:

chr2_12300_12350  11000_13000
chr1_34500_34550   33000_44000

Thanks,

Are all of the entries non-overlapping - or to say it another way: Can you reuse some lines from file2?

Yes, we can reuse the file2... Just we need to see if file1 ranges are falling between file2 ranges or not..

Hi, try:

awk -F_ 'NR==FNR{R[$1]=$2;next} {for(i in R)if(i<=$2 && R>=$3)print $0,i FS R}' file2 file1

Hi,

The code does not work..

Thanks,

Hi.

If that is indeed what you meant, then consider:

When you provide useful information, you are more likely to receive solutions quickly and on-point.

Best wishes ... cheers, drl

1 Like

Hi,

Sorry. I dint mean to be harsh or say it dint work.. When I used the code provided it just executed with no error message and no output. I understand that this forum is to help others and people try to take out some time from their busy schedule to do this..

Let me explain my question more clearly..

Of the two files which I have I am trying to check if my file1 positions fall between file 2 ranges. If so I need to assign the file 2 position to my file1.

Thanks,

What OS and version are you using, Diya123?