Search last column of INPUT.txt in TABLEs text and add correspond columns to INPUT.txt

Hi dears
i use bash shell

i have INPUT.txt
like this
number of columns different in one
some row have 12 , some 11 columns

see last column

  INPUT.txt
 CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic
  63 M 27 BS/BA TEHRANI 3 4 298320 310050 11730 j j 
 63 M 27 BS/BA TEHRANI 3 4 310050 311430 1380     a 
 63 M 27 BS/BA TEHRANI 3 4 311430 312080 650 ] ]
 

and two TABLE text like this.have two columns.

  TABLE1.txt
 j feat1
 a feat2 
.
 .
 .
   
  TABLE2.txt
 j sp1
 a sp2
 .
 .
 

I want to add two columns to INPUT.txt
search last column of INPUT in TABLEs text and add correspond columns to INPUT
(i think can merge TABLEs like j feat1 sp1)
and output like this

  output.txt
 CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic feat sp
 63 M 27 BS/BA TEHRANI 3 4 298320 310050 11730 j j feat1 sp1
 63 M 27 BS/BA TEHRANI 3 4 310050 311430 1380       a feat2 sp2
 63 M 27 BS/BA TEHRANI 3 4 311430 312080 650 ] ] . . 
.
.
 

thanks all

In your sample INPUT.TXT, the header line has 11 fields as "CODE" and "GENDER" are contiguous which they are not in the data lines.
How do you determine the two new header fields?

Howsoever, try (with file1 .. file3 representing your input / tables)

awk '
function CKCOM(T, X)    {if (!T) return X
                         for (i=1; i<=length(T) && substr(T, i, 1) == substr(X, i, 1); i++);
                         return substr (T, 1, i-1)
                        }
FNR == 1        {FN++
                 T[$NF] = OFS HD[1] OFS HD[2]
                }

FN < 3          {T[$1] = T[$1] OFS $2
                 HD[FN] = CKCOM(HD[FN], $2)
                 next
                }

                {print $0 T[$NF]
                }
' file[1-3]
CodeGender Age Grade Dialect Session Sentence Start End Length Phonemic Phonetic feat sp
63 M 27 BS/BA TEHRANI 3 4 298320 310050 11730 j j  feat1 sp1
63 M 27 BS/BA TEHRANI 3 4 310050 311430 1380   a  feat2 sp2
63 M 27 BS/BA TEHRANI 3 4 311430 312080 650 ] ]
awk '
FILENAME ~ /TABLE/ {w[$1]=w[$1] " " $2; next}
NR > 1 {$0=$0 w[$NF]}
{print $0}
' TABLE1.txt TABLE2.txt INPUT.txt