Rereading your question, I think you are just missing the
-i option to
sed. That is the option that makes
sed edit the file in place rather than printing the results to standard output.
Note that it is a very good idea to test your
sed command before using the
-i switch, as there is no "undo" command if you get it wrong.
So, for example, if you run
sed 's/old/new/' myfile, you will see the contents of
myfile printed out on your terminal with the first instance of
old on each line replaced with
new. If you run
sed -i 's/old/new/' myfile, you won't see anything printed out—
myfile will be (irrevocably) edited in place.
You can also use, for example,
-i.bak instead of
-i, which will cause the original file to be saved as
myfile.bak and the edited file to appear as
myfile. (You can define whatever extension you want instead of
.bak and it doesn't need to start with a dot, but
.bak is conventional to use for this purpose.)
Quotes around your space-containing filename is a separate issue and the answer to that is simple—use double quotes to get variable expansion without word splitting. So if you have a variable
filenamevariable="My file name which contains spaces", you need to refer to it like so:
sed 's/old/new/' "$filenamevariable"
Some other recommended reading: