Fixes for non-GNU tail and sed, plus a few OSX-specific fixes