即使顶级目录没有.txt文件,'grep -R string * .txt'也是如此 [英] 'grep -R string *.txt' even when top dir doesn't have a .txt file

查看:140
本文介绍了即使顶级目录没有.txt文件,'grep -R string * .txt'也是如此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不记得在 grep 中引入了递归搜索' -R '命令行开关时,但现在我无法想象没有它的生活。



唯一的问题是,如果递归中的任何目录没有匹配文件名通配符,则grep -R将停止并将无法报告目录和文件这样做会产生正面的搜索结果。

例如:

  grep -R skeleton_app * .xml 

只会报告

  AndroidManifest.xml:< application android:label =@ string / skeleton_app> 

同时:

  grep -R skeleton_app * 

会报告所有内容:

  AndroidManifest.xml:< application android:label =@ string / skeleton_app> 
二进制文件bin / classes.dex匹配
二进制文件bin / com / example / android / skeletonapp / R $ string.class匹配
gen / com / example / android / skeletonapp/R。 java:public static final int skeleton_app = 0x7f050000;
res / values / strings.xml:< string name =skeleton_app>了解Intents< / string>

我的问题:有没有办法告诉' grep -R '' 停止文件名不匹配?

解决方案

b $ b

  grep -R --include'* .xml'skeleton_app。 


I don't recall when the recursive search '-R' command line switch was introduced in grep, but now I can't imagine life without it.

Its only problem is that if any directory in the recursion doesn't have a match for the filename wildcard, grep -R will stop and will fail to report the directories and files that do produce positive search results.

For example:

  grep -R skeleton_app *.xml

Will report only

AndroidManifest.xml:    <application android:label="@string/skeleton_app">

While:

  grep -R skeleton_app *

Will report all:

AndroidManifest.xml:    <application android:label="@string/skeleton_app">
Binary file bin/classes.dex matches
Binary file bin/com/example/android/skeletonapp/R$string.class matches
gen/com/example/android/skeletonapp/R.java:        public static final int skeleton_app=0x7f050000;
res/values/strings.xml:    <string name="skeleton_app">Understanding Intents</string>

My question: Is there a way to tell 'grep -R' not to stop on filename mismatch?

解决方案

Try:

grep -R --include '*.xml' skeleton_app .

这篇关于即使顶级目录没有.txt文件,'grep -R string * .txt'也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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