Global Search & Replace Using vi Editor
By Angsuman Chakraborty, Gaea News NetworkSaturday, August 30, 2008
To perform a global search and replace in vi editor, use the search and replace command in command mode:
:%s/search_string/replacement_string/g
The
%
is a shortcut that tells vi to search all lines of the file forsearch_string
and change it toreplacement_string
. The global (g
) flag at the end of the command tells vi to continue searching for other occurrences ofsearch_string
. To confirm each replacement, add the confirm (c
) flag after the global flag. via Indiana University
For example I just needed to replace all instances of GROUP with GROUP_ (to import schema from MS Access to MySQL database). Here is the command I used:
:%s/GROUP/GROUP_/g
Nirmal Kumar