OK, I see now. You have to read the lookup file into a big datastructure, then referencing with the individual files is easy.
$ cat script.awk
BEGIN {OFS = "\t"}
NR==1 {
for (i=1; i<=NF; i++)
label[i] = $i
next
}
NR==FNR {
for (i=1; i<=NF; i++)
for (j=1; j<=NF; j++)
if (i != j)
value[label[i],$i,label[j]] = $j
next
}
FNR==1 {
split(FILENAME, a, /\./)
j = a[1]
}
{
$(NF+1) = value[$1,$2,j]
print
}
$ awk -f script.awk lookup.txt 030-031.txt
070-291 4 2
070-031 3 2
$ awk -f script.awk lookup.txt 070-031.txt
030-031 5 6
070-291 8 7
This version is a bit more compact, and passes the filenames in your preferred order:
$ script.awk
BEGIN {OFS = "\t"}
NR==1 {
split(FILENAME, a, /\./)
dest = a[1]
}
NR==FNR {
src[$1]=$2
next
}
FNR==1 {
for (i=1; i<=NF; i++)
col[$i]=i
next
}
{
for (from in src)
if ($col[from] == src[from])
print from, src[from], $col[dest]
}
$ awk -f script.awk 030-031.txt lookup.txt
070-031 3 2
070-291 4 2
$ awk -f script.awk 070-031.txt lookup.txt
030-031 5 6
070-291 8 7