Question

I have some log files that end in times

1200.gz
1215.gz
1230.gz
1245.gz
1300.gz

When I want to search through all the 12 o'clock files, I do zcat 12**.gz | grep whatever but it usually takes too long. Is there a way to use a regex "or" zcat 12(00|15)? This tutorial makes it seem like I can just use square braces, but I get a command not found error.

Was it helpful?

Solution 2

Why are you using zcat and grep? You can directly use zgrep command to search for a pattern in compressed files:

zgrep 'whatever' 12{00,15}.gz

OTHER TIPS

That's nothing to do with the (z)cat command, it's a shell issue.

It seems like good old brace expansion should work for this case:

$ zcat 12{00,15}.gz | grep whatever

With , you could use extended globbing

shopt -s extglob
zcat 12@(00|15).gz | grep text

Why not use zgrep if available

zgrep text 12@(00|15).gz 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top