Ismail Degani
Ismail Degani

Reputation: 887

Grepping from a text file list

I know I can find specific types of files and then grep them in one shot, i.e.

find . -type f -name "*.log" -exec grep -o "some-pattern" {} \;

But I need to do this in two steps. This is because the find operation is expensive (there are lots of files and subdirectories to search). I'd like to save down the file-list to a text file, and then repeatedly grep for different patterns on this precomputed set of files whenever I need to. The first part is easy:

find . -type f -name "*.log" > my-file-list.txt

Now I have a file that looks like this:

./logs/log1.log
./logs/log2.log
etc

What does the grep look like? I've tried a few combinations but can't get it right.

Upvotes: 9

Views: 8093

Answers (1)

aragaer
aragaer

Reputation: 17848

xargs grep "your pattern" < my-file-list.txt

Upvotes: 21

Related Questions