You might try something like this if you don't want to create a file:
echo '%s/oldtext/newtext/g\nwq' | ex file
This will edit the text within the file. Non interactive style vi. The exact syntax for ex is a bit murky I can't find a lot of docs on it, but in a few occasions it's well worth figuring out and using.