The first file contain a list of code and numbers. The second file only the number.
I would like to replace the corresponding code in the first column of the file1 with the corresponding value in column1 (and just in column1) of file2 so to have:
output
CCC;.;.;.
BBB;.;.;.
Hope this is clear,
Please notice that not all of the code are contained as number in file two and also the two file are not in order.
awk '
# NR is the total number of lines processed so far
# FNR is the line number in the present file
# When they are the same, that means awk is reading the first file.
# So, when reading the first file, load elements into A like
# A["33"]="BBB" for easy lookup later.
# $1 and $2 are the first and second columns in the line, respectively.
NR==FNR { A[$2]=$1; next }
# If the first column is found in A's array indexes, then
# set the first column to the data for A[$1].
$1 in A { $1=A[$1] }
# Print every line ( Prints whenever the statement is true, and 1 is always true)
#
# FS is the input column separator, OFS is the output column separator.
# Any number of variables can be specified before files by putting VARNAME=value.
#
# After that comes the list filenames to process in order.
1' FS=";" OFS=";" file1 file2 > file3