Grep a gzipped file?

794 views Asked by At

I would like to see if there is a title url in the following gzip file:

curl -O http://www.imdb.com/sitemap_US_02002.xml.gz
grep 'imdb.com/title/tt' sitemap_US_02002.xml.gz

Is there a way to do this 'on the fly', perhaps even in a one-liner?

2

There are 2 answers

0
Amber On BEST ANSWER

If you mean you just want to do this in a pipelined fashion, this should work:

curl http://www.imdb.com/sitemap_US_02002.xml.gz | zcat | grep 'imdb.com/title/tt'
0
nobody On

Many systems (Linux and OS X at least) come with a zgrep utility that will gzip-decompress its input and then run the result through grep. Like so:

curl http://www.imdb.com/sitemap_US_02002.xml.gz | zgrep 'imdb.com/title/tt'