查找匹配词

Find matching words

我有语料库文件和规则文件。我正在尝试查找语料库中出现规则中的词的匹配词。

# cat corpus.txt
this is a paragraph number one
second line
third line

# cat rule.txt
a
b
c

这returns 2行

# grep -F0 -f rule.txt corpus.txt
this is a paragraph number one
second line

但我期待这样的 4 个词...

a
paragraph
number
second

尝试使用 grep 或 awk 获得这些结果。

假设单词由空格分隔

awk '{print "\S*" "\S*"}' rule.txt | grep -m 4 -o -f - corpus.txt