search for matching value between lists

Hello. I have two very large files, file1 and file2. File1 has two columns of paired numbers eg.
2 5
9 17
47 700
File1 has one column of numbers eg.
5
7
76

I would like to search in file2 for numbers that are greater than or equal to the values from column1 of file1 but less then or equal to values from column2 of file1 and then print out matching numbers from both files. I am trying to use awk to do this but am having problems. Any suggestions?

What is the desired output for your sample input?

The desired output from the example would be
2 5 5
47 700 76
The first two columns would be from file1 and the last column from file2

Try:

awk 'NR==FNR{a[NR]=$1;next}a[FNR]>=$1&&a[FNR]<=$2{print $0" "a[FNR]}' file2 file1

The following code will work:

#!/usr/bin/ksh
while read mNbr; do
  while read mFrom mTo; do
    if [[ ${mNbr} -ge ${mFrom} && ${mNbr} -le ${mTo} ]]; then
      echo "${mNbr} ${mFrom} ${mTo}"
      break
    fi
  done < Target_Numbers
done< Source_Numbers

Here is an example:
Source_Numbers:

2
5
7
23
76

Target_Numbers:

2 5
9 17
47 700

Result:

2 2 5
5 2 5
76 47 700

Thanks. When I use this program I get this message on every line.

")syntax error: invalid arithmetic operator (error token is "
my files have large numbers like 6280051. Could this be a problem? Also should I reverse which is target file and which is source file?

---------- Post updated at 05:51 PM ---------- Previous update was at 05:37 PM ----------

Thanks but I don't get anything to stndout. Also I am using large numbers with up to 7 digits eg 6500431. Could this be a problem?

A signed 32-bit integer type (a conservative common denominator for a long while now) can represent an integer ranging from approximately 2 billion to negative 2 billion. 7 million-ish is not a problem.