It's pretty straight-forward:
awk 'FNR == NR { a[FNR] = $1; next }
FNR != NR { if (a[FNR] == $2) print $3 }' file1.txt file2.txt
The first line saves the value of $1
for each line in file1.txt
(and skips the rest of the script).
The second line doesn't formally need the FNR!=NR
condition, but I think it makes it clearer. It processes file2.txt
. If the value in $2
is equal to the corresponding saved value, print $3
.
If the files are too big to save the $1
values from file1.txt
in memory, you should have said so and you have to work harder. It can still be done with awk
; it just isn't as neat and tidy and awk
-ish.