无需解压就可查看压缩包内文本文件的内容

  • 组合使用zcat和head(或tail)[依赖于Linux系统]

1
2
3
4
man zcat
man head
man tail
zcat FILE.gz | head
  • Perl脚本(相当于zcat与head合用)[依赖于Perl及相应模块]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl 
 
use strict;
use warnings;
 
use Getopt::Std;
use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError);
 
my %opts = ( n =10 );
getopts( 'n:', %opts );
die(
    qq/
Usage:    headZip.pl [options] 《FILE》
 
Options:  -n INT   The number of lines. [$opts{n}]
n/
) if ( @ARGV1 );
 
my $fi = $ARGV[0];
my $n  = $opts{n};
 
my $z = new IO::Uncompress::AnyUncompress $fi
  or die "anyuncompress failed: $AnyUncompressErrorn";
 
for ( my $i = 0 ; $i$n ; $i++ ) {
    my $line = $z-》getline();
    print "$line";
}

相关模块:

IO::Uncompress::AnyUncompress
Gzip::RandomAccess

PS:还不知道如何写出类似于zcat和tail组合使用的脚本,熟悉这个的朋友告知一声。