Wow. I've only ever used sed for simple regex operations, reading this has opened up a whole new world for me.
... I will force myself not to make use of it because you're a bad influence and I already have to stop myself from using too much grep/sed/awk magic, but this is seriously impressive, and an entertaining read. Well done!