Johnathan Au
Johnathan Au

Reputation: 5362

How can I search for a file that contains a pattern and then search within all those files with another pattern?

Basically, I want to do something like:

Locate log4j.xml 

which will give me over 20 results. Then I want to search within all these files for "iwjboss".

Is there a command that locates and then finds text within all these files bearing in mind that I don't know the directory of all the log4j.xml files?

Upvotes: 0

Views: 44

Answers (2)

anubhava
anubhava

Reputation: 785146

Yes there is a command it is called find.

Try this command for find and grep combined:

find . -name "log4j.xml" -exec grep "iwjboss" '{}' \;

Upvotes: 0

Alex Jurado - Bitendian
Alex Jurado - Bitendian

Reputation: 1027

Doing something with the result of something is achieved like this:

grep iwjboss `locate log4j.xml`

Upvotes: 1

Related Questions