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.

Eg:

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


Output:


Sep 9 17:12:47 145.247.1.62 cap-s12-custfw-1: NetScreen
device_id=cap-s12-custfw-1 [Root]system-information-00542: BGP peer
10.24.224.187 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.*145.247.1.62' $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.*145.247.1.62\|145.247.1.62.*BGP' $dir/*.gz.)

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