[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1570
  • Last Modified:

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$sourcefile\n";

   my $tfilelist = "$sourcefile.txt";
   $tfilelist =~ s/source\.{1}(.*)0000-0400\.trace\.gz/$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.
0
uluttrell
Asked:
uluttrell
  • 2
  • 2
  • 2
1 Solution
 
ozoCommented:
my @patterna = `$gzgrep '$patterna' $sourcefile` ;
0
 
uluttrellAuthor Commented:
Thanks Ozo, but I'm getting this error:  sh: syntax error at line 1: `(' unexpected.  I am using bash.
0
 
fim32Commented:
change:
my $patterna = "AlphaBetaGamma\(4,0\)";
to:
my $patterna = 'AlphaBetaGamma\(4,0\)';
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
fim32Commented:
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?
0
 
ozoCommented:
Did you put in the ' (not `) that I showed?
0
 
uluttrellAuthor Commented:
Ozo, no, I did not.  When I did place the ' it worked.  Thank you.  Apologies for overlooking that.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now