Reading the name of a file in a .gz

Y

Yoda Pugsley

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
 
J

Jim Gibson

Yoda Pugsley said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top