Unix命令列出包含字符串的文件,但是* NOT *包含另一个字符串 [英] Unix Command to List files containing string but *NOT* containing another string
问题描述
如何递归查看包含一个字符串且没有其他字符串的文件列表?此外,我的意思是评估文件的文本,而不是文件名。
结论:
根据注释,我最后使用:
查找。 -name* .html-exec grep -lR'base\-maps'{} \; | xargs grep -L'base \-maps \ -bot'
-maps而不是base-maps-bot。
grep -rl< string-to-match> | xargs grep -L< string-not-to-match>
说明: grep -lr
(r)输出包含< string-to-match>
的所有文件的列表(l)。 xargs循环遍历这些文件,在每个文件上调用 grep -L
。 grep -L
只会在文件不包含< string-not-to-match>
。
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.
Conclusion:
As per comments, I ended up using:
find . -name "*.html" -exec grep -lR 'base\-maps' {} \; | xargs grep -L 'base\-maps\-bot'
This returned files with "base-maps" and not "base-maps-bot". Thank you!!
Try this:
grep -rl <string-to-match> | xargs 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>
.
这篇关于Unix命令列出包含字符串的文件,但是* NOT *包含另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!