Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grepping from a text file list

Tags:

grep

shell

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.

like image 318
Ismail Degani Avatar asked Feb 01 '13 21:02

Ismail Degani


1 Answers

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

like image 97
aragaer Avatar answered Sep 20 '22 16:09

aragaer