Some versions of sed distribution (namely RedHat and family) have added the -c option, which does this, in which case see @Isaac answer.
But for those with unpatched GNU sed, the easiest way I've found is to simply replace perl, which overwrites files similar to sed -c when they are available. The following commands are basically equivalent:
sed -ci 's/find/replace/' perl -pi -e 's/find/replace/'
Just donβt worry too much and do perl -pie ; for example, sed -ie instead of interpreting as another parameter, it will use e as an argument for -i and use it as a suffix to back up the source file. See perldoc perlrun .
Perl's regex parsing is slightly different than sed (better, imo) for more complex things: generally speaking, use less backslashes.
source share