I want to compare the 1st column of one file with all columns of the second file and if match found print the first column (1st file) and the complete row where match found in the second file.
Example Input file_1
RAM_1
RAM_2
RAM_3
RAM_4
RAM_5
RAM_6
Example Input file_2
RAM_7 RAM_3
RAM_8 RAM_10 RAM_15 RAM_2
RAM_6 RAM_16 RAM_4
RAM_11 RAM_5 RAM_18 RAM_20 RAM_19
RAM_1 RAM_8 RAM_9 RAM_12
Expected Output
RAM_1 RAM_1 RAM_8 RAM_9 RAM_12
RAM_2 RAM_8 RAM_10 RAM_15 RAM_2
RAM_3 RAM_7 RAM_3
RAM_4 RAM_6 RAM_16 RAM_4
RAM_5 RAM_11 RAM_5 RAM_18 RAM_20 RAM_19
RAM_6 RAM_6 RAM_16 RAM_4
I have tried for fix number of column but it print only fist line of file.
awk 'NR==FNR{a[$1]=$0} $1 in a && $2 in a && $3 in a{print a[$1] ORS a[$2] ORS a[$3]}' file_2 file_1