#!/usr/bin/env perl # irccolor -- filter to colorize the output of irclogs # usage: irclogs sr.ht | irccolor | less -R use strict; use warnings; use Term::ANSIColor; # No black (bg), white (text/msg), bright white, or bright black (time) my @colors = qw( red green yellow blue magenta cyan bright_red bright_green bright_yellow bright_blue bright_magenta bright_cyan ); my $i = 0; my %user_colors; while (my $line = <>) { if ($line =~ m{(\d\d\d\d-\d\d-\d\d).log:\[(\d\d:\d\d:\d\d)]\s*(<[^>]+>)(.*)}) { my ($date, $time, $user, $msg) = ($1, $2, $3, $4); print color("bright_black"); print "[$date $time] "; print color("reset"); if (!exists $user_colors{$user}) { $user_colors{$user} = $colors[$i % @colors]; $i++; } print color("$user_colors{$user}"); print $user; print color("reset"); print "$msg\n"; } else { # Don't know how to colorize! print "$line"; } }