Global Search & Replace Using vi Editor

By Angsuman Chakraborty, Gaea News Network
Saturday, 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 for search_string and change it to replacement_string. The global ( g ) flag at the end of the command tells vi to continue searching for other occurrences of search_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

Filed under: Database, How To

Tags: , , ,
Discussion

Nirmal Kumar
March 25, 2010: 1:07 am

In vi how do we replace with

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :