Python:在两个文件中查找公共文本

Sam*_*Sam -3 python sed gawk

让我给出示例文本文件:

例如在file1.txt中数据是: -

qwer
asdf
zxcv
1234
Run Code Online (Sandbox Code Playgroud)

file2.txt中数据是: -

0987
5678
uiop
qwer
zxcv
Run Code Online (Sandbox Code Playgroud)

期望的结果:

qwer
zxcv
Run Code Online (Sandbox Code Playgroud)

我如何得到这个结果?我想用pythongawksed.

NPE*_*NPE 5

我会为此使用Python集:

file1 = set(line.strip() for line in open('file1.txt'))
file2 = set(line.strip() for line in open('file2.txt'))

for line in file1 & file2:
    if line:
        print line
Run Code Online (Sandbox Code Playgroud)