Commit | Line | Data |
642e522c |
1 | #!/usr/bin/perl |
f4c6fd49 |
2 | |
3 | use strict ; |
8aa25532 |
4 | use warnings ; |
642e522c |
5 | use IO::Uncompress::Gunzip qw($GunzipError); |
f4c6fd49 |
6 | |
642e522c |
7 | die "Usage: gzgrep pattern [file...]\n" |
8 | unless @ARGV >= 1; |
f4c6fd49 |
9 | |
10 | my $pattern = shift ; |
f4c6fd49 |
11 | my $file ; |
12 | |
642e522c |
13 | @ARGV = '-' unless @ARGV ; |
14 | |
15 | foreach $file (@ARGV) { |
16 | my $gz = new IO::Uncompress::Gunzip $file |
17 | or die "Cannot uncompress $file: $GunzipError\n" ; |
18 | |
19 | while (<$gz>) { |
20 | print if /$pattern/ ; |
21 | } |
22 | |
23 | die "Error reading from $file: $GunzipError\n" |
24 | if $GunzipError ; |
25 | } |
26 | |
27 | __END__ |
f4c6fd49 |
28 | foreach $file (@ARGV) { |
29 | my $gz = gzopen($file, "rb") |
30 | or die "Cannot open $file: $gzerrno\n" ; |
31 | |
32 | while ($gz->gzreadline($_) > 0) { |
33 | print if /$pattern/ ; |
34 | } |
35 | |
36 | die "Error reading from $file: $gzerrno\n" |
37 | if $gzerrno != Z_STREAM_END ; |
38 | |
39 | $gz->gzclose() ; |
40 | } |