Like many open source folks, I consider irc a crucial piece of every day infrastructure. I use bip as a proxy to help me keep up with conversations that occurred while I was away. The next time I connect with my client (xchat, in this case), I get a playback of the old conversations, and my client does the right thing, highlighting tabs if my name was mentioned, etc.
Sometimes though, I want to read old logs, either to remind myself of a conversation I had with someone, or to dig out a URL, or whatever. bip keeps these logs around, but they can be annoying to read.
Here’s an example of how bip stores the logs:
achiang@complete:~/.bip$ ls -R .: bip.conf bip.pid logs ./logs: bip.log canonical freenode oftc sekrit ./logs/freenode: 2011-03 2011-04 2011-05 2011-06 2011-07 ./logs/freenode/2011-03: achiang.30.log #coherellc.31.log #ubuntu-devel.31.log chanserv.30.log #ubuntu-motu.30.log chanserv.31.log #ubuntu-motu.31.log #coherellc.30.log #ubuntu-devel.30.log
They’re just free form text, which is good, because you can then use normal tools like grep on them. Unfortunately, they’re also full of long, noisy lines that look like:
achiang@complete:~/.bip$ head ./logs/freenode/2011-03/#ubuntu-devel.31.log 31-03-2011 00:01:48 -!- firstname.lastname@example.org has joined #ubuntu-devel 31-03-2011 00:03:05 -!- T0rCh__!~T0rCh_rao@220.127.116.11 has quit [Remote host closed the connection] 31-03-2011 00:06:23 -!- holstein!~holstein@unaffiliated/mikeh789 has quit [Ping timeout: 240 seconds] 31-03-2011 00:08:23 -!- email@example.com has quit [Ping timeout: 276 seconds] 31-03-2011 00:08:48 -!- firstname.lastname@example.org has joined #ubuntu-devel 31-03-2011 00:12:02 -!- email@example.com has joined #ubuntu-devel 31-03-2011 00:12:03 -!- firstname.lastname@example.org has quit [Changing host] 31-03-2011 00:12:03 -!- holstein!~holstein@unaffiliated/mikeh789 has joined #ubuntu-devel 31-03-2011 00:15:35 -!- email@example.com has joined #ubuntu-devel 31-03-2011 00:20:32 -!- TeTeTfirstname.lastname@example.org has joined #ubuntu-devel
So just viewing them in an editor can be annoying.
And that was a rather long intro to describe what is one of the world’s most trivial scripts (which has at least one known bug :-/ ). But anyway, I call the snippet below “bipcat”:
#!/bin/sh cat $1 | grep -v "has quit" | grep -v "is now known as" | grep -v "has joined" | grep -v "has left" | sed 's/!.*:/:/' | cut -f 2- -d' '
And now, you can get much more sensible output:
achiang@complete:~/.bip$ bipcat ./logs/freenode/2011-03/#ubuntu-devel.31.log | head 00:54:45 < dholbach: good morning 01:05:16 < pitti: Good morning 01:58:29 < pitti: should bug 685682 be closed with the new fglrx that we landed yesterday? 01:58:32 < ubottu://launchpad.net/bugs/685682 01:59:08 < didrocks: it seems that cnd still have that issue with the driver and workarounded compiz 01:59:41 < didrocks: anyway, there is still a need for a compiz upload which will come with other fixes (probably Monday) 01:59:48 < pitti: ah, thanks 02:00:09 < tseliot: the fix should be available in the next upload of compiz (it's already available in a daily PPA) 02:00:28 < pitti: so I guess for now the fglrx tasks should be closed then? 02:00:30 < didrocks: yeah, but as told, it's not working on cnd's machine, I asked him to check with you and jay
[the bug is that the sed line does a greedy match, so it replaces everything up to the last ':', which is clearly not the right thing to do if someone actually typed in a ':'. suggestions for improvement welcome]