in reply to Best way to edit a file?

echo ',s/foo/bar/g wq'|ed somefile

Yes, that's a newline halfway through the command.