Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by talexb (Chancellor)
on Dec 03, 2010 at 22:06 UTC ( [id://875284]=note: print w/replies, xml ) Need Help??


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

I was told about zgrep recently and was gobsmacked that I'd never heard of it before. Don't know if that will do the trick, but give it a shot.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

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

Replies are listed 'Best First'.
Re^2: Parse a tar.gz file without unzipping and uncompressing unzipping?
by tod222 (Pilgrim) on Dec 04, 2010 at 01:44 UTC

    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.

      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.

Re^2: Parse a tar.gz file without unzipping and uncompressing unzipping?
by rizzy (Sexton) on Dec 04, 2010 at 00:47 UTC
    Thanks, Alex. That may have been what my friend was referring to. He said he wasn't sure if what he had in mind would work with tarred files.

    I'm not sure how this squares with some of the other responses in this thread, though.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-16 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found