Solved

Grep Gzipped files

Posted on 2004-04-27
6
1,552 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl 101 11 81
Exchange 2010 Transport Rule Regex 28 118
PHP pack() : What exactly is meant by signed char and unsigned char? 7 118
perl getopt long help 34 70
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

809 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