unixgrepbz2

Is there any way to parellelly grep through bz2 files


I recently found out this solution to less through compressed gz files parellelly based on the cores available.

find . -name "*.gz" | xargs -n 1 -P 3 zgrep -H '{pattern to search}'

P.S. 3 is the number of cores

I was wondering if there was a way to do it for bz2 files as well. Currently I am using this command:

find -type f -name '*.bz2' -execdir bzgrep "{text to find}" {} /dev/null \;

Solution

  • Change *.gz to *.bz2; change zgrep to bzgrep, and there you are.

    For a bit of extra safety around unusual filenames, use -print0 on the find end and -0 on the xargs:

    find . -name "*.bz2" -print0 | xargs -0 -n 1 -P 3 bzgrep -H '{pattern to search}'