查找包含两种模式的所有文件 [英] Find all files containing two patterns

查看:51
本文介绍了查找包含两种模式的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找包含2个特定字符串的所有文件.它需要同时匹配string1和string2.到目前为止,我已经尝试过:

I'm trying to find all files that contain 2 specific strings. It needs to match both string1 AND string2. What I've tried so far:

find ~ -type f -name "*.txt" -exec grep -lie 'string1' -lie 'string2' {} \;

但是,这似乎找到了string1或string2.如何找到所有同时包含string1和string2的文件?

But this seems to find string1 OR string2. How can I find all files containing both string1 AND string2?

在这种情况下,我试图查找同时包含字符串'sed'和'lynx'的所有文档

In this specific case, I'm trying to find all documents that contain both strings 'sed' and 'lynx'

find ~ -type f -name "*.txt" -exec grep -lie 'sed' -lie 'lynx' {} \;

推荐答案

即使字符串不在同一行,也可以这样做:

This will do, even when the strings are not on the same line:

find〜-type f -name \ *.txt -exec grep -iq string1 \ {\} \;-exec grep -iq string2 \ {\} \;-打印

这篇关于查找包含两种模式的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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