GNU Sed on the macOS
Like a lot of systems folks I use sed, a lot. It is probably an unhealthy amount of sed use but so be it. I operate on a lot of Linux servers but my desktop environment of choice is Mac OS X which means BSD tools (not the Linux-y GNU tools).
The differences are relatively subtle between BSD sed and GNU sed. However, most of my work is done through Terminal. I frequently find myself diving rabbit holes and I really do not want to have to remember the differences between BSD and GNU sed.
Of course if you have homebrew you can install gnu-sed from it. This is more like a simple, single action solution. Anyway if you want only the Gnu-sed without brew you can compile it on Mac OS X:
It does not appear obvious to me that any internal OS X processes depend on BSD sed. The one annoyance I need to note when fully replacing the BSD sed version by following these steps is that after every OS update (10.11.4 to 10.11.5, etc.) you will have to run through all these steps again.
For me, it is all about consistently having the same sed everywhere. Most people either do not notice the difference or just deal with them. I choose not to and you are free to choose differently too.
Disable Mac OS X System Integrity Protection (if you are going to have GNU sed as your default sed this is a requirement)
Install Xcode (via Mac App Store)
Install Xcode Command Line Tools:
Download the latest version of GNU sed from http://ftp.gnu.org/gnu/sed/
Untar the sed package you just downloaded
Open Terminal and cd into the unpacked GNU sed directory and configure the package:
./configure --prefix=/usr/ --program-suffix=-gnu
- Compile Gnu-sed:
make -j 16
- Install it:
sudo make install
- Here is why disabling SIP is needed. Move the system's sed to another file:
mv /usr/bin/sed /usr/bin/sed-bsd
- Now create a link from gnu-sed to the default sed path:
ln -s /usr/bin/sed-gnu /usr/bin/sed
If by any chance you need the regular system's sed (BSD sed) simply call it from its new name
bsd-sed or recreate the link pointing to it:
ln -sf /usr/bin/sed-bsd /usr/bin/sed