Help with replace column one content based on reference file

Input file

1 testing 10 20 1
A testing 20 40 1
3 testing 23 232 2
1 testing 10 243 2
.
.

Reference file

1 final
3 used
.
.

Output file

final testing 10 20
A testing 20 40
used testing 23 232
final testing 10 243
.
.

I would like to replace those content that shown in column 1 of input file with the content that shown in reference file (if available).
Thanks.

nawk 'FNR==NR{ref[$1]=$2;next} $1 in ref{$1=ref[$1]}1' refFile inputFile
awk 'NR==FNR{a[$1]=$2;next}{$1=a[$1]?a[$1]:$1}1' ref_file input
1 Like