Only the data file has to be retained in memory, so the index file can be of an arbitrary size.
If your data file is 1 million lines of about 40 characters, it should fit in 40 Mb, which is a breeze for your average PC.
Re-opening the data file to fetch one line at a time would be way slower, even with disk caching.
So I think you could safely go for a solution that would fetch the entire data file into memory.
Here is how I would do it in awk:
gawk "{if(NR==FNR)l[NR]=$0; else print l[$1] }" data.txt numbers.txt
With this input
data.txt
1 1.000000 -1.072000 -1.000000
2 2.000000 -1.213000 1.009900
3 -1.210000 -1.043000 1.000000
4 -1.000000 -1.000000 -1.000000
5 1.000000 1.000000 -0.9999991.000000 -1.072000 -1.000000
6 2.000000 -1.213000 1.009900
7 -1.210000 -1.043000 1.000000
8 -1.000000 -1.000000 -1.000000
9 1.000000 1.000000 -0.9999991.000000 -1.072000 -1.000000
10 2.000000 -1.213000 1.009900
11 -1.210000 -1.043000 1.000000
12 -1.000000 -1.000000 -1.000000
13 1.000000 1.000000 -0.9999991.000000 -1.072000 -1.000000
14 2.000000 -1.213000 1.009900
15 -1.210000 -1.043000 1.000000
16 -1.000000 -1.000000 -1.000000
17 1.000000 1.000000 -0.9999991.000000 -1.072000 -1.000000
18 2.000000 -1.213000 1.009900
19 -1.210000 -1.043000 1.000000
20 -1.000000 -1.000000 -1.000000
(I added an index in front of your sample data for testing).
numbers.txt
1
5
1
4
2
20
1
it produces
1 1.000000 -1.072000 -1.000000
5 1.000000 1.000000 -0.9999991.000000 -1.072000 -1.000000
1 1.000000 -1.072000 -1.000000
4 -1.000000 -1.000000 -1.000000
2 2.000000 -1.213000 1.009900
20 -1.000000 -1.000000 -1.000000
1 1.000000 -1.072000 -1.000000
Performance test
I used this PHP script to generate a test case:
<?php
$MAX_DATA = 1000000;
$MAX_INDEX = 5000000;
$contents = "";
for ($i = 0 ; $i != $MAX_DATA ; $i++) $contents .= ($i+1) . " " . str_shuffle("01234567890123456789012345678901234567890123456789") . "\n";
file_put_contents ('data.txt', $contents);
$contents = "";
for ($i = 0 ; $i != $MAX_INDEX ; $i++) $contents .= rand(1, $MAX_DATA) . "\n";
file_put_contents ('numbers.txt', $contents);
echo "done.";
?>
With a random input of 1M data and 5M indexes, the awk script above took about 20 seconds to produce a result on my PC.
The data file was about 56 Mb and the awk process consumed about 197 mb.
As one could have expected, the processing time is roughly proportional to the size of the index file for a given set of data.