簡體   English   中英

zcat讀取gzip文件,然后在Perl中將它們串聯

[英]zcat to read gzip files and then concatenate them in Perl

我需要編寫一個perl腳本,以從其路徑的文本文件列表中讀取壓縮文件,然后將它們連接在一起並輸出到新的壓縮文件中。 (我需要在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";

我無法以某種方式使其運行。 另外,如果有人可以指導正確的方式輸出此壓縮文件。

謝謝!

您不需要為此使用perl。 您甚至不需要zcat / gzip,因為壓縮文件支持cat

cat $(cat pathfile) >resultfile

但是,如果您真的需要結合以下方法來嘗試獲得額外的壓縮:

zcat $(cat pathfile)|gzip >resultfile

添加:還請注意右側的第一個“相關”鏈接,該鏈接似乎已經回答了這個問題: 如何連接兩個或多個gzip文件/流

感謝您的答復-腳本現在運行良好-

#!/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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM