I have two files like this:File 1apple fruit 10 4strawberry fruit 22 11berry fruit 33 33ball toy 1 12straw thing 2 33File 2strawberry straw berryrawberry raw berryI want to compare column 1 of file 2 with column 1 of file 1, column 2 of file 2 with column 1 of file 1, column 3 of file 2 with column 1 of file 1. If match is found, I want to display all three matching lines from file 1.Here, the output should be:strawberry fruit 22 11straw thing 2 33berry fruit 33 33How can I do this?
How to compare multiple columns of one file with one column of another and display matches from second file?
text processing;awk;grep;text
$ awk 'NR==FNR{a[$1]=$0} $1 in a && $2 in a && $3 in a{print a[$1] ORS a[$2] ORS a[$3]}' file1 file2strawberry fruit 22 11straw thing 2 33berry fruit 33 33Save lines based on first column of file1 and then print matching lines if all three columns of file2 lines match