Reading the name of a file in a .gz

Discussion in 'Perl' started by Yoda Pugsley, Apr 8, 2004.

  1. Yoda Pugsley

    Yoda Pugsley Guest

    Hello,

    I need to read the name of a file inside a .gz. I know it should be the
    zipped name - .gz, but the filenames are long and truncated sometimes. In
    perl, what is the command to read the gzip -l into a variable? Something
    like


    my ($filename)

    $filename == gzip -l ~/cdr/file.gz

    will that work, or something like it?

    Thanks,
    JH
    Yoda Pugsley, Apr 8, 2004
    #1
    1. Advertising

  2. Yoda Pugsley

    Jim Gibson Guest

    In article <Xns94C59E1CBDCEBheretherecom@65.32.1.8>, Yoda Pugsley
    <> wrote:

    > Hello,
    >
    > I need to read the name of a file inside a .gz. I know it should be the
    > zipped name - .gz, but the filenames are long and truncated sometimes. In
    > perl, what is the command to read the gzip -l into a variable? Something
    > like
    >
    >
    > my ($filename)
    >
    > $filename == gzip -l ~/cdr/file.gz
    >
    > will that work, or something like it?
    >
    > Thanks,
    > JH


    The following might work, provided your gzip program produces two lines
    of output with the file name in the fourth field of the second line:

    #!/usr/local/bin/perl
    use strict;
    use warnings;

    my $f = 'file.gz';
    $_ = (`gzip -l $f`)[1];
    my $filename = (split)[3];
    print "filename: $filename\n";

    FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
    Jim Gibson, Apr 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    810
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,790
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,380
    Joe Smith
    Apr 22, 2007
  4. Jack-2
    Replies:
    3
    Views:
    255
    Jack-2
    Dec 24, 2003
  5. Java  script  Dude

    IE name="name" & form.name property bug

    Java script Dude, Jun 29, 2004, in forum: Javascript
    Replies:
    5
    Views:
    228
    Java script Dude
    Jun 30, 2004
Loading...

Share This Page