Grep 在目录中的所有文件中搜索 string1 和 string2 [英] Grep Search all files in directory for string1 AND string2

查看:15
本文介绍了Grep 在目录中的所有文件中搜索 string1 和 string2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 cygwin 中使用 grep 查找所有包含 BOTH 词的文件.

How can I make use of grep in cygwin to find all files that contain BOTH words.

这是我用来递归搜索目录中所有文件的一个词:

This is what I use to search all files in a directory recursively for one word:

grep -r "db-connect.php" .

如何扩展上述内容以查找同时包含db-connect.php"和version"的文件.

How can I extend the above to look for files that contain both "db-connect.php" AND "version".

我试过这个: grep -r "db-connect.php|version" . 但这是一个 OR,即它获取包含一个或另一个的文件.

I tried this: grep -r "db-connect.php|version" . but this is an OR i.e. it gets file that contain one or the other.

感谢大家的帮助

推荐答案

grep -r db-connect.php . | grep version

这篇关于Grep 在目录中的所有文件中搜索 string1 和 string2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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