user7315541 user7315541 - 4 years ago 117
Linux Question

Find a line in a list of .gz files

i around 50 .gz files in a particular directory in linux. i need to find a particular line in each file. currently i am doing by zcat each file.


zcat 20160909-custfw.log.7.gz | zgrep BGP | zgrep


Sep 9 17:12:47 cap-s12-custfw-1: NetScreen
device_id=cap-s12-custfw-1 [Root]system-information-00542: BGP peer changed to Idle state (2016-09-09 17:13:15)

please let me if there is any easier way to do this.

Answer Source

What about zgrep 'BGP.*' $dir/*.gz?

(Or to achieve equivalent results to your sequence of two zgrep calls, you would have to zgrep also the inverse order of the two regexes, sth like zgrep 'BGP.*\|*BGP' $dir/*.gz.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download