Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parallel grep pattern multiple files

I'm searching successfully with this command : search for a list of suspicious IPs from a txt file ips.txt in a logs directory (compressed files).

root@yop# find /mylogs/ -exec zgrep -i -f ips.txt {} \; > ips.result.txt

I want now to use parallel with it.. to speed up the search. I'm not able to find correct args for it at the moment.. I mean use the pattern file (one per line) and also export it in a result file.

Is there any parallel guru for it please ?

The more close command i found was this : grep-or-anything-else-many-files-with-multiprocessor-power

But wasn't able to use it with a file list of patterns and export results to a file too...

Please help, thanks all.

like image 422
mastarah Avatar asked Feb 25 '14 11:02

mastarah


People also ask

How do you use parallel grep?

Get GNU parallel (e.g. brew install parallel , apt-get install parallel , etc.). Run grep in parallel blocks on a single file. Run grep on multiple files in parallel, in this case all files in a directory and its subdirectories. Add /dev/null to force grep to prepend the filename to the matching line.


1 Answers

If you just want to run multiple jobs at once, consider using GNU parallel:

parallel zgrep -i -f ips.txt :::: <(find /mylogs -type f) > results.txt
like image 87
Steve Avatar answered Oct 04 '22 22:10

Steve