Find all matched lines from two files

Hello, everyone

I have two files like this:

File 1:

A              
B                
C
D
E
F

File 2:

A B 1
A C 2
A K 3
B A 4
D E 3
W X 2 
A B 2

I want to print all lines (file2) that the first two columns are consist of elements from file1.
So, what I expected is :

A B 1
A B 2
A C 2
B A 4
D E 3

Could anyone help me ? Thanks in advance.

Hi, try:

awk 'NR==FNR{A[$1]; next} $1 in A && $2 in A' file1 file2
1 Like

great, thanks very much.