This command will replace occurrences of foo with bar in the file X in-place and create a backup of X in X.old:
$ sed -i.old "s/foo/bar/g" filename