Solved

Grep Gzipped files

Posted on 2004-04-27
6
1,548 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
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

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 …
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…
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…

832 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