Reputation: 644
I want find the file containing some text but that should start with some character.
grep -inr "my text" .
The above command will show all the files containing the above text. But what I want is if the file contains a text and the name should starts with like E*.
Upvotes: 1
Views: 5208
Reputation: 116
If you want a max-depth for 1 layer, then i think most efficient way would be...
grep <pattern> E*
for multiple levels you can use like this
grep <pattern> */*/E*
Upvotes: 0
Reputation: 14949
You can use this,
find . -name 'E*' -exec grep -Hl "sample" {} \;
Explanation:
-H
: Print the file name for each match.
-l
: Suppress normal output
Upvotes: 5
Reputation: 42935
You can combine find
and grep
:
find . -name "E*" | xargs grep -nH "my text"
You can also use find
s exec
parameter instead of xargs
. Take a look at its man mange for this: man find
Upvotes: 1