Running vi within a bash script and executing vi commands to edit another file

something like this as a bash script:

#!/bin/bash
vi filename.txt -c ':g/^/m0' -c ':wq'

where -c execute a command. Here the command is to reverse the lines in a textfile. After done, :wq to save and exit. (man vi to get more about -c)

If you don't want to type -c twice, you can do it this way:

vi -c "g/^/m0 | wq" filename.txt

For scripted editing tasks, you can use ed instead of vi:

ed runner2 <<'END'
1,$s/gout:/xtl/
1,$s/gout:/dat/
w
q
END

For global line-oriented search and replace, sed is a good choice:

sed -i 's/gout:/xtl/; s/gout:/dat/' runner2