Vi isn't meant to be used in scripts, only interactively. The preferred method in this situation would be to use sed.
To do a find and replace with sed you would use:
Code:
sed -i 's/searchterm/replacement/g' filename.txt
This will replace all occurrences of searchterm with replacement in the file filename.txt
You can add the find command to do this over multiple files at the same time, for example to do a find and replace in every file in a directory you could do:
Code:
find /home/user/directory -type f -exec sed -i 's/searchterm/replacement/g' {} \;
Bookmarks