I want to write a Bash shell script that does the following:
Recently, I have answered a similar question, “Automated editing of several files in Vim”. May be the solution that I describe there will satisfy your needs.