vermaraj
vermaraj

Reputation: 644

Find files containing text using grep command starts with file name charector

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

Answers (3)

Kaze..Sujan
Kaze..Sujan

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

sat
sat

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

arkascha
arkascha

Reputation: 42935

You can combine find and grep:

find . -name "E*" | xargs grep -nH "my text"

You can also use finds exec parameter instead of xargs. Take a look at its man mange for this: man find

Upvotes: 1

Related Questions