Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'grep -R string *.txt' even when top dir doesn't have a .txt file

Tags:

grep

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?

like image 646
Android Eve Avatar asked Dec 13 '22 15:12

Android Eve


1 Answers

Try:

grep -R --include '*.xml' skeleton_app .
like image 59
yan Avatar answered Mar 24 '23 06:03

yan