I am new to shell scripting and trying to grep some text in multiple gz files using awk. My code
zcat log*.gz | awk{awk logic goes here}
but the above takes a lot of time to sift through prod logs.Is there any way to make it run faster?
I am new to shell scripting and trying to grep some text in multiple gz files using awk. My code
zcat log*.gz | awk{awk logic goes here}
but the above takes a lot of time to sift through prod logs.Is there any way to make it run faster?
You might see some output faster if you loop over the files instead of uncompressing them all at once:
for log in log*.gz; do
zcat "$log" | awk 'awk logic goes here'
done
I wrote a script called zawk which can do this natively. It's similar to glenn jackman's answer but it handles awk
options and several different compression mechanisms and input methods while retaining FILENAME
and FNR
.
You'd use it like:
zawk 'awk logic goes here' log*.gz