Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

unzipping files with .gz extension

by Anonymous Monk
on Dec 29, 2012 at 16:59 UTC ( #1010828=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Need to unzip files with .gz extension and have to zip it back.Can anyone help please? Thanks

Comment on unzipping files with .gz extension
Re: unzipping files with .gz extension
by roboticus (Canon) on Dec 29, 2012 at 17:15 UTC

    The .gz suffix implies a gzip compressed file. If you go to CPAN and search for gzip, you'll find several modules that will help solve your problem. I can't recommend which one to use, as I've not used any of them. Perhaps another monk will chime in with a recommendation.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: unzipping files with .gz extension
by ww (Bishop) on Dec 29, 2012 at 17:35 UTC
    Is this a Perl question or are you merely dropping a line in anything that looks like water?

    If Perl-related, show us what you've tried and where you're stuck... or simply follow roboticus suggestion and see what you find. If the topic is not Perl, maybe a little searching the web will work better than asking at a Perl-specific site.

Re: unzipping files with .gz extension
by ansh batra (Friar) on Dec 29, 2012 at 17:53 UTC

    do you need a perl script for that?
    if yes
    then please try it urself ,you'll feel good trying it urself
    try this and this

      Hi, I need perl script itself.My code is throwing an error like this Can't locate loadable object for module PerlIO::gzip in @INC (@INC contains: C:/ Perl/site/lib C:/Perl/lib .) at unzip2.pl line 1 Compilation failed in require at unzip2.pl line 1. BEGIN failed--compilation aborted at unzip2.pl line 1.

      use PerlIO::gzip; open( IN, "<:gzip", test1.txt.gz ) or die "open failed\n"; while (<IN>) { print $_; }

        Pop on over to CPAN and install PerlIO::gzip, then.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

Re: unzipping files with .gz extension
by space_monk (Chaplain) on Dec 29, 2012 at 19:59 UTC
    Most tar commands also unzip files (and can create them): for unzipping, tar xvzf yourfile.gz will probably work on Linux and a lot of other Unix systems without going near Perl. Its a bit dirty, but if you are doing it in a Perl script, you can do that as a system command enclosed in backticks. However the other methods suggested are much more preferable if you are doing this within Perl. Update - ignore this reply. I should have read the question more carefully.. :-(
    A Monk aims to give answers to those who have none, and to learn from those who know more.
      Most tar commands also unzip files (and can create them): for unzipping, tar xvzf yourfile.gz will probably work on Linux and a lot of other Unix systems without going near Perl. Its a bit dirty, but if you are doing it in a Perl script, you can do that as a system command enclosed in backticks. However the other methods suggested are much more preferable if you are doing this within Perl.

      This is nonsense!

      GNU tar can decompress on the fly, but it DOES NOT decompress non-tar files:

      /tmp>gzip foo.txt /tmp>tar xvzf foo.txt.gz tar: This does not look like a tar archive tar: Skipping to next header tar: Exiting with failure status due to previous errors /tmp>dir total 1 -rw-r--r-- 1 alex users 527 Dec 29 21:21 foo.txt.gz /tmp>

      If you choose to use external tools, use the proper tools. tar is the wrong tool for handling arbitary gzip-compressed files. gzip with the -d switch, gunzip, and zcat are the right tools.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: unzipping files with .gz extension
by pvaldes (Chaplain) on Dec 29, 2012 at 23:21 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1010828]
Front-paged by 2teez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-07-29 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls