First off, it’s not safe – unless there’s a temporary file name in the middle.
When you’ve got a file open for reading (sed input), you don’t want to be writing to the same output file. Most likely outcomes would be file truncation or file corruption.
You don’t specify if you’re running in a *nix environment or a windows or cygwin environment. But it might go something like this…
sed s/oldstuff/newstuff < $file > tempfile
cp -f tempfile $file
Bear in mind that the syntax might not be quite right, since I just did this off the top of my head. You can also have the original filename passed as a parameter to the shell script.