我有一个语料库文件和规则文件。我试图找到匹配的词,其中从规则出现在语料库中。
# cat corpus.txt
this is a paragraph number one
second line
third line
# cat rule.txt
a
b
c这将返回2行
# grep -F0 -f rule.txt corpus.txt
this is a paragraph number one
second line但我期待像这样的四个词..。
a
paragraph
number
second尝试使用grep或awk实现这些结果。
发布于 2022-02-01 10:10:46
假设单词被空格隔开
awk '{print "\\S*" $1 "\\S*"}' rule.txt | grep -m 4 -o -f - corpus.txt
https://stackoverflow.com/questions/70938265
复制相似问题