Sed 101

This works with GNU sed, but not on OS X:

$ sed -i -e 's/foo/bar/' target.file
$ sed -i'' -e 's/foo/bar/' target.file

This works on OS X, but not with GNU sed:

$ sed -i '' -e 's/foo/bar/' target.file

On OS X,

  • can’t use sed -i -e since the extension of the backup file would be set to -e
  • can’t use sed -i’’ -e for the same reasons—it needs a space between -i and ‘’.

or using Perl

$ perl -pi -e s,foo,bar,g target.file