ed is perfect in shell scripts:
% cat <<- _EOF_ | ed -s filename
ed commands...
_EOF_
works on all UNIX-like operating systems and it means that temporary files are no longer necessary. (GNU sed -i is an architectural violation of the idea of a stream editor, and it isn't available everywhere.)