how to search for a particular string from a .gz file?

一个人想着一个人 提交于 2020-02-19 09:33:11

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/24218032/how-to-search-for-a-particular-string-from-a-gz-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!