Fix for sad sed

I love that Mac OS X is really BSD under the hood, but sometimes it causes unexpected pain. More than once I’ve tripped over the differences in date between Linux and Mac OS X, and over this weekend I’ve had trauma with sed.

Specifically, if I have a single character I want to replace in a file – like replacing an out-of-band delimiter in a flat file with a TAB character – I’d normally say sed 's/\d197/\d009/g' < foo > bar. Sadly, this doesn’t work with Mac OS X’s sed.

Ruby to the rescue, in the form of my own sadsed.rb:

And then just ./sadsed.rb foo > bar and away you go.

And for the record: I’m dealing with some big files, and Ruby’s Regexp is pretty snappy.

CSS Floats and Quantum Mechanics

Yesterday, I spent more time dealing with the getting floated page elements to look right than I care to admit. I am not kidding when I say that I found quantum mechanics more intuitive than I find CSS floats now.

Of course, I put more effort into studying quantum mechanics. And maybe there’s some similarity here – once you learn a few hairy rules and what they really mean, the weird results make sense.

That was more gripe-y than educational. I’ll post something meatier next time.