Patch to support OS X.

The sed on OS X is ancient and limited.  If you have git, you have
perl so this should be fine everywhere.  Haven't done perl in yonks
though so this might not be idiomatic - but it does seem to work
correctly.