Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Parse a tar.gz file without unzipping and uncompressing unzipping?

by tod222 (Pilgrim)
on Dec 04, 2010 at 01:44 UTC ( #875309=note: print w/replies, xml ) Need Help??


in reply to Re: Parse a tar.gz file without unzipping and uncompressing unzipping?
in thread Parse a tar.gz file without unzipping and uncompressing unzipping?

By using zcat you can set up a pipeline to uncompress and extract the files from the archive as a stream without using temporary files or needing to hold everything in RAM.

On Linux the code looks like this:

#!/usr/bin/perl use strict; use warnings; my $file = shift; my $pipecmd = "zcat $file | tar -O -xf -"; # -O, extract files to sta +ndard output open(my $PIPEIN, '-|', $pipecmd) or die "Opening pipe [$pipecmd]: $!\n +"; while ( my $line = <$PIPEIN> ) { chomp $line; print "$line\n"; # do parsing here }

A Windows version of gzip is available from The gzip home page. I'm not sure if the Win version includes zcat.

You'll need a Windows tar as well. I'm not sure if the pipe command will work in Windows.

This may need better handing of file not found and other errors from the pipe command, but it should get you started.

  • Comment on Re^2: Parse a tar.gz file without unzipping and uncompressing unzipping?
  • Download Code

Replies are listed 'Best First'.
Re^3: Parse a tar.gz file without unzipping and uncompressing unzipping?
by ctilmes (Vicar) on Dec 06, 2010 at 14:13 UTC
    my $pipecmd = "zcat $file | tar  -O -xf -"; # -O, extract files to standard output

    Your tar may even have support for uncompressing built in, look for the tar option "-Z" for uncompress and "-z" for unzip.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://875309]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2022-09-25 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?