Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Parse log file with double records.

Posted on 2003-03-12
3
Medium Priority
?
160 Views
Last Modified: 2012-05-04
Hi, what I would like to do is to parse each line of a log file for a specific pattern, for example,

if ($array[5] eq "misc")
{
  $usertotal{$array[5]}++;
}


and if the pattern be found, then increment a counter by one.  So far so good, my problem is that some of the records in the file have been logged twice.  What I would like to do is to decrement the counter by one in the case that every next line has the same time ($array[2]) with its previous line's.

A sample of my log file is the following:

Mar 12 06:00:50 localhost kernel:  misc info.
Mar 12 06:00:50 localhost kernel:  misc info.
Mar 12 06:00:51 localhost kernel:  test data.
Mar 12 06:00:53 localhost kernel:  misc info.
Mar 12 06:00:53 localhost kernel:  misc info.
Mar 12 06:01:01 localhost kernel:  misc info.

Thank you very much in advance.
0
Comment
Question by:Anastasios
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 750 total points
ID: 8124455
while( <LOG> ){
    @array = split;
    next if $array[2] eq $prev[2] && $array[5] eq $prev[5];
    $usertotal{$array[5]}++;
    @prev = @array;
}
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8125353
$prev = "";
while(<stdin>) {
 if ( $prev eq $_) { next; }
  ($array[0],$array[1],$array[2]$array[3]$array[4]) = split(/ /);
   $usertotal{$array[5]}++;
} # end of while


hope this helps

 
0
 
LVL 3

Expert Comment

by:prady_21
ID: 8125364
i am sorry, i forgot one more line
At the end of while loop, just add this
$prev = $_;

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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
Suggested Courses

564 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