how to search for a particular string from a .gz f

2020-06-07 19:33发布

I want to search for a particular string from a .gz file containing a text file without extracting in linux terminal. I know how to search for a string from a text file using grep "text to search" ./myfile.txt. But how to make it work for .gz files?

标签: linux grep gzip
2条回答
祖国的老花朵
2楼-- · 2020-06-07 20:29
gunzip -c mygzfile.gz | grep "string to be searched"

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

查看更多
时光不老,我们不散
3楼-- · 2020-06-07 20:35

You can use zgrep. Usage is similar to grep.

zgrep "pattern" file.gz

From the man page's description:

Zgrep invokes grep on compressed or gzipped files. All options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep.

查看更多
登录 后发表回答