Reading the name of a file in a .gz

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yoda Pugsley

    Reading the name of a file in a .gz

    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
  • Jim Gibson

    #2
    Re: Reading the name of a file in a .gz

    In article <Xns94C59E1CBDC EBheretherecom@ 65.32.1.8>, Yoda Pugsley
    <here@there.com > wrote:
    [color=blue]
    > 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[/color]

    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.

    Comment

    Working...