?
Solved

Parse log file with double records.

Posted on 2003-03-12
3
Medium Priority
?
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 84

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans
Suggested Courses

752 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