#!/usr/bin/perl # parse.pl - extract date, name, and text from irc log # Eric Lease Morgan # February 12, 2011 - first cut # configure use constant LOG => './irclog.txt'; # require use strict; # initialize my $date = ''; open INPUT, ' < ' . LOG or die "Can't open " . LOG . ": $!\n"; while ( ) { # re-initialize my $time = ''; my $text = ''; my $name = ''; # clean chop; # check for day change if ( /^--- Day changed/ ) { /^--- Day changed \w\w\w (.*)$/; my ( $month, $day, $year ) = split / /, $1; # map the month if ( $month eq 'Jan' ) { $month = '01' } elsif ( $month eq 'Feb' ) { $month = '02' } elsif ( $month eq 'Mar' ) { $month = '03' } elsif ( $month eq 'Apr' ) { $month = '04' } elsif ( $month eq 'May' ) { $month = '05' } elsif ( $month eq 'Jun' ) { $month = '06' } elsif ( $month eq 'Jul' ) { $month = '06' } elsif ( $month eq 'Aug' ) { $month = '08' } elsif ( $month eq 'Sep' ) { $month = '09' } elsif ( $month eq 'Oct' ) { $month = '10' } elsif ( $month eq 'Nov' ) { $month = '11' } elsif ( $month eq 'Dec' ) { $month = '12' } else { # error print "Unknown value for month: $month. Call Eric.\n"; next; } $date = $year . '-' . $month . '-' . $day; next; } # actual transaction else { # extract date and text /^\[(\d\d:\d\d:\d\d)\](.*)/; $time = $1; $text = $2; # skip, for now, "processing instructions" if ( $text =~ / ---\|/ ) { next } # trap "me" comment elsif ( $text =~ / \* / ) { $text =~ s/ \*// } # clean $text =~ s/ +/ /g; $text =~ s/^ //; $text =~ s/ $//; # extract name from normal transaction if ( $text =~ /^\w+ \|/ ) { $text =~ /^(\w+) \| (.*)/; $name = $1; $text = $2; } # extract name for "me" comment else { $text =~ /^(\w+) /; $name = $1; } } # date stamp; my $datestamp = "$date $time"; # echo #print " date stamp: $datestamp\n"; #print " name: $name\n"; #print " text: $text\n"; #print "\n"; # echo to "database" print "$datestamp\t$name\t$text\n"; } # done close INPUT; exit;