簡體   English   中英

使用perl,有沒有一種方法可以打開gzip文件並在不完全解壓縮的情況下通讀這些行?

[英]Using perl, is there a way to open gzip files and read through the lines without fully decompressing?

我基本上想為gzip做一個文件句柄,並像其他任何文件一樣使用它來匹配字符串。 我需要比較兩個gzip文件中的行,但它們分別為15 GB。 我正在使用Archive :: Extract和File :: temp來讀取它們,但我的硬盤空間已滿。

您可以將gzip -dc輸送到文件句柄中,如下所示:

 open(my $fh1, '-|', '/usr/bin/gzip -dc filename1.gz') or die $!;
 open(my $fh2, '-|', '/usr/bin/gzip -dc filename2.gz') or die $!;

它應該緩沖gzip的輸出,而不要占用磁盤上的空間。

PerlIO::gzip不會解壓縮整個文件,而是在讀取到句柄時解壓縮,因此您也可以使用它。

暫無
暫無

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

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