MoonPoint Support Logo

 

Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
September
Sun Mon Tue Wed Thu Fri Sat
       
10
 
2016
Months
Sep


Sat, Sep 10, 2016 10:41 pm

zgrep

If you wish to search for information within a .gz file produced by the gzip utility, which is a tool used for data compression, you don't have to uncompress the file first. Instead, you can use the zgrep utility. E.g., if I wished to search for the string "Splunk" in a gzip compressed text file, if I used grep, I wouldn't be able to find the text for which I was searching since the contents of the file were compressed, but I could find it with zgrep.

$ grep Splunk tools.txt.gz
$ zgrep Splunk tools.txt.gz
Splunk

You can use the same options with the zgrep command that you can use with grep - see zgrep man page. E.g., I could determine how many times the pattern for which I'm searching occurs in the file using the -c option.

$ zgrep -c "Splunk" tools.txt.gz
1
$

The zgrep utility is present by default on Mac OS X systems. You can run it from a command line interface by opening a Terminal window (Terminal is found in the /Applications/Utilities directory). It is also found on Linux systems. E.g., for CentOS Linux systems, it will be present if the gzip package has been installed.

$ rpm -q --whatprovides /usr/bin/zgrep
gzip-1.5-7.el7.x86_64
$

[/os/unix/commands] permanent link

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo