in reply to Searching a gzip file

If you want to search for a pattern, then do what Corion advised---decompress the file; however, you can look at the gzip and count the lines.
#!/usr/bin/perl use strict; use warnings; my $lines = 0; my $filename = '/path/to/ImageMagick.tar.gz'; die "Can't open '${filename}': $!" unless open(FILE, '<', $filename); while (sysread FILE, my $buffer, 4096) { $lines += ($buffer =~ tr/\n//); } print $lines, "\n";

Replies are listed 'Best First'.
Re^2: Searching a gzip file
by Corion (Patriarch) on Aug 26, 2010 at 11:42 UTC

    But a gzipped file is binary, and counting the newlines in a binary file does not make much sense.