Solved

Grep Gzipped files

Posted on 2004-04-27
6
1,543 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
Comment Utility
my @patterna = `$gzgrep '$patterna' $sourcefile` ;
0
 

Author Comment

by:uluttrell
Comment Utility
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
Comment Utility
change:
my $patterna = "AlphaBetaGamma\(4,0\)";
to:
my $patterna = 'AlphaBetaGamma\(4,0\)';
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 7

Expert Comment

by:fim32
Comment Utility
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
Comment Utility
Did you put in the ' (not `) that I showed?
0
 

Author Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now