How do I find files that do not contain a given string pattern?
如何找出当前目录中不包含单词
如果您的GREP有
1 | $ grep -L"foo" * |
看看
在
1 | ack -L foo |
下面的命令给出了不包含模式
1 | find . -not -ipath '.*svn*' -exec grep -H -E -o -c "foo" {} \; | grep 0 |
下面的命令不需要find通过使用第二个
1 | grep -rL"foo" ./* | grep -v"\.svn" |
您实际上需要:
1 | find . -not -ipath '.*svn*' -exec grep -H -E -o -c "foo" {} \; | grep :0\$ |
我很幸运
1 | grep -H -E -o -c"foo" */*/*.ext | grep ext:0 |
我尝试使用
打开错误报告
正如@tukan所评论的那样,AG有一份关于
- ggreer/银搜索者:238-
--files-without-matches 工作不正常
由于bug报告进展不大,因此不应依赖下面提到的
Any updates on this?
-L completely ignores matches on the first line of the file. Seems like if this isn't going to be fixed soon, the flag should be removed entirely, as it effectively does not work as advertised at all.
Silver Searcher-AG(预期功能-见错误报告)
作为
A code searching tool similar to ack, with a focus on speed.
从
1
2
3
4
5
6
7 ...
OPTIONS
...
-L --files-without-matches
Only print the names of files that don′t contain matches.
也就是说,从当前目录递归搜索不匹配
1 | ag -L foo |
要只搜索当前目录中与
1 | ag -L foo --depth 0 |
您可以在"find"下指定过滤器,在"grep-vwe"下指定排除字符串。如果还需要过滤修改的时间,请使用"查找"下的mtime。
我的grep没有任何-l选项。我确实找到了解决办法。
这些想法是:
使用diff命令对2个转储文件进行区分。
1 2 3 | grep 'foo' *.log | cut -c1-14 | uniq > txt1.txt grep * *.log | cut -c1-14 | uniq > txt2.txt diff txt1.txt txt2.txt | grep">" |
问题
我需要重构一个大型项目,该项目使用
解决方案
解释
管道前:
发现
格雷普
这将给我一个以
1 2 3 4 5 6 7 8 9 10 | $> find . -iname '*.phtml$' -exec 'grep -H -E -o -c 'new Mustache' {}'\; ./app/MyApp/Customer/View/Account/quickcodemanagestore.phtml:0 ./app/MyApp/Customer/View/Account/studio.phtml:0 ./app/MyApp/Customer/View/Account/orders.phtml:1 ./app/MyApp/Customer/View/Account/banking.phtml:1 ./app/MyApp/Customer/View/Account/applycomplete.phtml:1 ./app/MyApp/Customer/View/Account/catalogue.phtml:1 ./app/MyApp/Customer/View/Account/classadd.phtml:0 ./app/MyApp/Customer/View/Account/orders-trade.phtml:0 |
第一个管道
1 2 3 4 5 6 | $> find . -iname '*.phtml' -exec grep -H -E -o -c 'new Mustache' {} \; | grep :0$ ./app/MyApp/Customer/View/Account/quickcodemanagestore.phtml:0 ./app/MyApp/Customer/View/Account/studio.phtml:0 ./app/MyApp/Customer/View/Account/classadd.phtml:0 ./app/MyApp/Customer/View/Account/orders-trade.phtml:0 |
第二个管道
1 2 3 4 5 6 | $> find . -iname '*.phtml' -exec grep -H -E -o -c 'new Mustache' {} \; | grep :0$ | sed 's/..$//' ./app/MyApp/Customer/View/Account/quickcodemanagestore.phtml ./app/MyApp/Customer/View/Account/studio.phtml ./app/MyApp/Customer/View/Account/classadd.phtml ./app/MyApp/Customer/View/Account/orders-trade.phtml |
1 | grep -irnw"filepath" -ve"pattern" |
或
1 | grep -ve"pattern" < file |
上面的命令将在-v找到要搜索的模式的反转时给出结果。
下面的命令可以帮助您筛选包含子字符串"foo"的行。
1 | cat file | grep -v"foo" |