perl -ale '
$h{$F[0]}=$F[1],next if @ARGV;
my $k;
print s/\H+/$k++ ? $h{$&} : $&/reg;
' file1 file2
° Reading the first file, @ARGV holds the 2nd argument and hence returns true.
° Populate a hash %h with keys as gene names and the corresponding values from the second field, for each line of file1.
° for the second file, @ARGV shall hold nothing, and hence will return a false. The last two lines of code will be executed for each line of file2.
° Initialize the count variable each time a line of file2 is read. Then the \H+ shall match a nonhorizontal whitespace run of characters, iow, a field. And on the 2nd onwards the subs from gene name => gene number is triggered.
The sed editor with Gnu extensions can also do it:
sed -Ee '
# store file1 in hold
/^C/!{H;1h;d;}
# place a traveling marker \n\n at $2
s/$/ /
G
s/(\S+\s+)/&\n\n/
# effect gene name => gene number
:a
s/\n\n(\S+)[ ]+((.*\n)?\1\s+([0-9]+))/ \4\n\n\2/
ta
# take away marker and hold portion
s/\n\n.*//
' file1 file2