Skip to content

log viewing made easy

11/04/2012

A year or two ago I had written a script that would parse a log file take out all the numbers and then count the number of entries and output the parsed entries and the number of times it occurred. I wrote it in awk, it worked but it was sloooooooowwwwwww.

It kind of fell out of use with me, it was a good idea but my implementation wasn’t. I kept saying to myself I’d have to revisit it when low and behold I came across this site with a beautiful little perl script which does exactly what I wanted.

Funnily or not the code is not parsed correctly on the page so I’ve put it all together correctly here. This is what I have running on two machines in my workplace and I’ll roll it out to the rest as I go.

#!/bin/perl

while ( ) {
s/\d+/\#/g; # change digits to # signs
s/Mon|Tue|Wed|Thu|Fri|Sat|Sun/DAY/;
s/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/MON/; $count{$_}++;
}

for $line ( sort keys %count) {
print “$count{$line}: $line”; }

If you deal with logs try this thing out. It’ll help you to, at a glance, know if there is a trend in your logs rather than slogging through them line by line.

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: