Kamal Ahmed wrote: > Hi, > > I am new to perl, and would really appreciate if anyone can help me, with > this: > > Following are sample lines from log files > > I have to write a perl script which will parse all these files, and : > > 1. Count the number of "INFO" or whatever text is in the file, and print > only those lines that have INFO
Easy. > 2. I have to create a has table of these keys Don't know what that means - what keys. > 3. Later , would be able to further develop the script to do some analysis > as well. You need to fix your line wrapping so one can tell what constitues a line. I assumed that the date is the start of each line and any line that doesn't start with a date was wrapped from the prior line. Here's a start : use strict; use warnings; my @logtypes = qw(query shark workflow advisor activity binary); my @logfiles = ('das_query0.0.log', 'Shark.log', 'workflow_server_0.0.log', 'advisor.log', 'activity_container_0.0.log', 'das_binary0.0.log', ); my $INFO_cnt = 0; for (my $ii = 0; $ii < @logfiles; ++$ii) { my $type = $logtypes[$ii]; my $infile = $logfiles[$ii]; # process each file open IN, $infile or die "open $infile: $!"; while ($_ = <IN>) { # process lines in file if (/INFO/) { # move to specific sub if not on all log types ++$INFO_cnt; print $_; } # process line for this log type if ($type eq 'query') { process_query ($_); } elsif ($type eq 'shark'; process_shark ($_); } elsif ($type eq 'query'; process_workflow ($_); } elsif ($type eq 'query'; process_advisor ($_); } elsif ($type eq 'query'; process_activity ($_); } elsif ($type eq 'query'; process_binary ($_); } else { print STDERR, "Type and files not aligned\n"; } } close IN; } exit; #- - - - - - - - - - - - - - - - - - process_query { local $_ = shift; chomp; # split line into fields my @f = split ' '; # do something with @f } #- - - - - - - - - - - - - - - - - - process_shark { local $_ = shift; chomp; # split line into fields my @f = split ' '; # do something with @f } #- - - - - - - - - - - - - - - - - - process_workflow { local $_ = shift; chomp; # split line into fields my @f = split ' '; # do something with @f } #- - - - - - - - - - - - - - - - - - process_advisor { local $_ = shift; chomp; # split line into fields my @f = split ' '; # do something with @f } #- - - - - - - - - - - - - - - - - - process_activity { local $_ = shift; chomp; # split line into fields my @f = split ' '; # do something with @f } #- - - - - - - - - - - - - - - - - - process_binary { local $_ = shift; chomp; # split line into fields my @f = split ' '; # do something with @f } #- - - - - - - - - - - - - - - - - - __END__ -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs