uluttrell
asked on
Grep Gzipped files
Greetings Perl Experts,
This is not a homework assignment.
I want to use gzgrep within a perl script. I have written the following:
====Begin code.pl
#!/usr/local/bin/perl
use strict;
#use warnings;
use FileHandle;
#my $gzgrep = "/usr/bin/gzgrep";
##my $GZGREP = '/usr/bin/gzgrep';
my @sourcefiles = glob("source*.trace.gz");
#print "@sourcefiles\n";
foreach my $sourcefile(@sourcefiles) {
#my @vsrtracelines = $fh->getlines();
my $patterna = "AlphaBetaGamma\(4, 0\) ";
my @patterna = system "$gzgrep $patterna $sourcefile" ;
#my $results = `gzgrep $patterna $sourcefile`;
#print "@patterna\n";
#print "$patterna\n$gzgrep\n$sour cefile\n";
my $tfilelist = "$sourcefile.txt";
$tfilelist =~ s/source\.{1}(.*)0000-0400 \.trace\.g z/$1/gi;
my $fh_out = new FileHandle "> $tfilelist";
#print $fh_out "Total connections for $sourcefile\n";
my $pattern1 = " ";
}
===End code.pl
Neither of my gzgrep attempts are working.
TIA for your help.
This is not a homework assignment.
I want to use gzgrep within a perl script. I have written the following:
====Begin code.pl
#!/usr/local/bin/perl
use strict;
#use warnings;
use FileHandle;
#my $gzgrep = "/usr/bin/gzgrep";
##my $GZGREP = '/usr/bin/gzgrep';
my @sourcefiles = glob("source*.trace.gz");
#print "@sourcefiles\n";
foreach my $sourcefile(@sourcefiles) {
#my @vsrtracelines = $fh->getlines();
my $patterna = "AlphaBetaGamma\(4, 0\) ";
my @patterna = system "$gzgrep $patterna $sourcefile" ;
#my $results = `gzgrep $patterna $sourcefile`;
#print "@patterna\n";
#print "$patterna\n$gzgrep\n$sour
my $tfilelist = "$sourcefile.txt";
$tfilelist =~ s/source\.{1}(.*)0000-0400
my $fh_out = new FileHandle "> $tfilelist";
#print $fh_out "Total connections for $sourcefile\n";
my $pattern1 = " ";
}
===End code.pl
Neither of my gzgrep attempts are working.
TIA for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
change:
my $patterna = "AlphaBetaGamma\(4,0\)";
to:
my $patterna = 'AlphaBetaGamma\(4,0\)';
my $patterna = "AlphaBetaGamma\(4,0\)";
to:
my $patterna = 'AlphaBetaGamma\(4,0\)';
fyi -- if you're wondering what is getting passed to your gzgrep command, try printing it to the screen, like:
print "$gzgrep $patterna $sourcefile\n";
at least you'll be able to tell that "\(" turns into '(', whereas '\(' stays as '\(', see?
print "$gzgrep $patterna $sourcefile\n";
at least you'll be able to tell that "\(" turns into '(', whereas '\(' stays as '\(', see?
Did you put in the ' (not `) that I showed?
ASKER
Ozo, no, I did not. When I did place the ' it worked. Thank you. Apologies for overlooking that.
ASKER