A more portable approach then relying on GNU SED / FreeBSD SED; might be to use perl, if you know the language.
Code:
$ perl -i -pe 's/foo/bar/g' file
NB that because -i renames or deletes the original file before creating a new file of the same name, UNIX-style soft and hard links will not be preserved.
see perlre, perlrequick, perlreref, perlretut manual pages; if necessary for more advanced pattern matching notes.
__________________
My
Journal
Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.