Opening a file in vi and automatically save and quit this file using shell script

Hi friends,
In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script.

the code segment is:
------------------------------------------------------------

cd ~/netfpga/projects/scone/sw/
sudo vi cpuhw 

-------------------------------------------------------------

Can anyone please help me.
Thanks in anticipation

This sounds strange. vi is an interactive tool - how should the shellscript know that the actions done in vi are finished?
What is your final goal? Are you trying to modify a file? There are text processors like sed or awk that are designed for that.

Hello,

Could you please let us know that which kind of change you want to make to the file (expected input and expected output will be good for us to help).

Also it's a kind request please put all commands and their output to codes.
As per rules for this forum.

Thanks,
R. Singh