Awk parsing multiple gz files

↘锁芯ラ 提交于 2020-04-18 04:40:13

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/28351625/awk-parsing-multiple-gz-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!