Search code examples
linuxshellzcat

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.


Solution

  • Search them in parallel with GNU Parallel:

    parallel zgrep BGP {} ::: *.gz | grep 145.247.1.62
    

    If you know it only occurs once in each file, or are only interested in the first occurrence, use zgrep -m1 to avoid bothering to read the remainder of the file and stop on the first match.