列出包含字符串但 *NOT* 包含另一个字符串的文件的 Unix 命令 [英] Unix Command to List files containing string but *NOT* containing another string

查看:19
本文介绍了列出包含字符串但 *NOT* 包含另一个字符串的文件的 Unix 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何递归查看包含一个字符串但具体没有另一个字符串的文件列表?另外,我的意思是评估文件的文本,而不是文件名.

How do I recursively view a list of files that has one string and specifically doesn't have another string? Also, I mean to evaluate the text of the files, not the filenames.

结论:

根据评论,我最终使用了:

As per comments, I ended up using:

find . -name "*.html" -exec grep -lR 'base-maps' {} ; | xargs grep -L 'base-maps-bot'

这返回了带有base-maps"而不是base-maps-bot"的文件.谢谢!!

This returned files with "base-maps" and not "base-maps-bot". Thank you!!

推荐答案

试试这个:

grep -rl <string-to-match> | xargs grep -L <string-not-to-match>

说明:grep -lr 使 grep 递归 (r) 输出包含 的所有文件的列表 (l).xargs 循环遍历这些文件,在每个文件上调用 grep -L.grep -L 只会在文件不包含 <string-not-to-match> 时输出文件名.

Explanation: grep -lr makes grep recursively (r) output a list (l) of all files that contain <string-to-match>. xargs loops over these files, calling grep -L on each one of them. grep -L will only output the filename when the file does not contain <string-not-to-match>.

这篇关于列出包含字符串但 *NOT* 包含另一个字符串的文件的 Unix 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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