How to search for a specific line from a .gz file?

I want to find a specific line from a .gz file containing a text file without extraction in the linux terminal. I know how to search a string from a text file using grep "text to search" ./myfile.txt . But how to make it work with .gz files?

+6
source share
2 answers
 gunzip -c mygzfile.gz | grep "string to be searched" 

But this will only work if the .gz file contains a text file, which is true in your case.

+6
source

You can use zgrep . Usage is similar to grep .

 zgrep "pattern" file.gz 

From the description of the man page:

Zgrep calls grep for compressed or gzipped files. All options specified are passed directly to grep. If the file is not specified, then standard input is unpacked, if necessary, and served in grep. Otherwise, these files are uncompressed, if necessary, and Grep.

+17
source

Source: https://habr.com/ru/post/970831/


All Articles