Get specific values from a file, help

Dear all,

I have a specific problem that i cannot solve and I hope someone here can help me. :slight_smile:

I have two text files with one column of values.
Example:

File1:

67        
94                     
95                     
.
.

File2

0.1
0.003
0.5
.
.

File1 contains the row numbers that value I need from File2. For example the output should be like this:

Theoretical outfile:

0.4 (row 67 from File2)
0.5 (row 94 from File2)
0.1 (row 95 from File2)
etc...

Is it possible to do this with awk ?

I would really appritiate if someone can help me.

Thanks,
Laszlo

Hello Laszlo,

Following may help you in same.

awk 'FNR==NR{A[NR]=$0;next} ($0 in A){print A[$0]}' file2 file1

Thanks,
R. Singh

1 Like

Thank you! It works :slight_smile:

Try also

awk 'FNR==NR {A[$1];next} FNR in A' file1 file2
1 Like