This may seem oversimplified, but if the change I make trashes the original file, I have a backup. save in a file called sv:
cat >sv.new cp "$1" sv.bak cp sv.new "$1"
use:
cat <filename> | command | sv <filename>