Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Grep Gzipped files

Posted on 2004-04-27
6
Medium Priority
?
1,565 Views
Last Modified: 2012-06-21
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
Comment
Question by:uluttrell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 total points
ID: 10930165
my @patterna = `$gzgrep '$patterna' $sourcefile` ;
0
 

Author Comment

by:uluttrell
ID: 10930246
Thanks Ozo, but I'm getting this error:  sh: syntax error at line 1: `(' unexpected.  I am using bash.
0
 
LVL 7

Expert Comment

by:fim32
ID: 10930490
change:
my $patterna = "AlphaBetaGamma\(4,0\)";
to:
my $patterna = 'AlphaBetaGamma\(4,0\)';
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Expert Comment

by:fim32
ID: 10930510
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
 
LVL 84

Expert Comment

by:ozo
ID: 10930714
Did you put in the ' (not `) that I showed?
0
 

Author Comment

by:uluttrell
ID: 10930775
Ozo, no, I did not.  When I did place the ' it worked.  Thank you.  Apologies for overlooking that.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question