-1

我需要编写一个 perl 脚本来从其路径的文本文件列表中读取 gzip 文件,然后将它们连接在一起并输出到一个新的 gzip 文件。(我需要在 perl 中执行此操作,因为它将在管道中实现) 我不确定如何完成 zcat 和连接部分,因为文件大小将以 Gbs 为单位,我需要注意存储和运行时间也是。

到目前为止,我可以将其视为-

use strict;
use warnings;
use IO::Compress::Gzip qw(gzip $GzipError) ;

#-------check the input file specified-------------#

$num_args = $#ARGV + 1;
if ($num_args != 1) {
    print "\nUsage: name.pl Filelist.txt \n";
exit;

$file_list = $ARGV[0];

#-------------Read the file into arrray-------------#

my @fastqc_files;   #Array that contains gzipped files 
use File::Slurp;
my @fastqc_files = $file_list;


#-------use the zcat over the array contents 
my $outputfile = "combined.txt"
open(my $combined_file, '>', $outputfile) or die "Could not open file '$outputfile' $!";

for my $fastqc_file (@fastqc_files) {

    open(IN, sprintf("zcat %s |", $fastqc_file)) 
      or die("Can't open pipe from command 'zcat $fastqc_file' : $!\n");
    while (<IN>) {
        while ( my $line = IN ) {
          print $outputfile $line ;
        }
    }
    close(IN);

my $Final_combied_zip = new IO::Compress::Gzip($combined_file);
  or die "gzip failed: $GzipError\n";

不知何故,我无法让它运行。另外,如果有人可以指导输出此压缩文件的正确方法。

谢谢!

4

2 回答 2

1

为此,您不需要 perl。您甚至不需要 zcat/gzip,因为 gzip 文件cat能够:

cat $(cat pathfile) >resultfile

但是如果你真的需要尝试通过组合来获得额外的压缩:

zcat $(cat pathfile)|gzip >resultfile

添加:还要注意右边的第一个“相关”链接,它似乎已经回答了这个问题:如何连接两个或多个 gzip 文件/流

于 2015-12-01T15:45:13.857 回答
1

感谢您的回复-脚本现在运行良好-

#!/usr/bin/perl
use strict;
use warnings;
use File::Slurp;
use IO::Compress::Gzip qw(gzip $GzipError);


my @data = read_file('./File_list.txt');
my $out = "./test.txt";


foreach my $data_file (@data)

{
    chomp($data_file);
    system("zcat $data_file >> $out");
}
my $outzip = "./test.gz";
gzip $out => $outzip;
于 2015-12-03T16:40:21.717 回答