You can use ed , a text-based text editor with similar commands for vi and vim. This is probably preceded by vi and vim.
In the script (using the document here, which processes the input before the EndCommand token), it will look like this:
ed file <<EndCommands 5 s/foo/bar/g 7 s/foo/bar/g wq EndCommands
Obviously ed commands can also be used on the command line.
suspectus Jun 26 '13 at 12:24 2013-06-26 12:24
source share