如何用单词列表grep [英] How to grep with a list of words

查看:101
本文介绍了如何用单词列表grep的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件A,其中有100个单词,以新行分隔。我想搜索文件B以查看文件A中是否有任何单词出现在它中。

I have a file A with 100 words in it separated by new lines. I would like to search file B to see if ANY of the words in file A occur in it.

我尝试了以下操作,但对我无效:

I tried the following but does not work to me:

grep -F A B


推荐答案

您需要使用 -f 选项:

You need to use the option -f:

$ grep -f A B

选项 -F 执行固定字符串搜索,其中 -f 用于指定模式文件。

The option -F does a fixed string search where as -f is for specifying a file of patterns. You may want both if the file only contains fixed strings and not regexps.

$ grep -Ff A B

您可能还希望 -w 选项仅用于匹配整个单词:

You may also want the -w option for matching whole words only:

$ grep -wFf A B

阅读 man grep ,了解所有可能的参数以及它们的作用。

Read man grep for a description of all the possible arguments and what they do.

这篇关于如何用单词列表grep的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆