Linux/unix下 grep 使用与(and)、或(or)关系搜索多个关键词
有时我们需要使用grep命令在一个文件中查找多个单词,或在同一行中查找多个单词。
这时候我们就需要使用grep and 或 or 同时搜索多个关键词。
下面我们来介绍下具体案例:
匹配文件中的多个单词,它们之间的关系为或(or) 关系
一行中多个关键词只要出现一个即匹配成功。
➜ grep -e “hello” -e “world” test.txt

我们也可以使用grep 正则,实现上述相同功能。
➜ grep -E “hello|world” test.txt

在一行中匹配多个单词,它们之间的关系是与(and)
一行中多个关键词必须同时出现。
➜ grep -e “hello” test.txt| grep -e “world”

相关推荐
-
第18问:MySQL CPU 高了,怎么办?2025-02-24 10:27:18
-
mysql索引类型 normal, unique, full text
mysql索引类型 normal, unique, full text2025-02-24 10:05:05 -
uwsgi+django+nginx 搭建部分总结2025-02-24 10:03:33
-
使用Docker配置Nginx环境部署Nextcloud2025-02-24 10:02:03
-
Nginx安装和怎么使用2025-02-24 10:00:45