Yes, vi is cryptic. But this command is useful for performing find and replace functions within the vi editor. First, hit ESC (escape), and the colon key (:) to get to the ex shell. Then enter:
%s/searchString/replaceString/g
An example will be:
:%s/WindowsNT/RedHatLinux/g
This is a repository of all of my Linux/Unix writings as well as useful tips and tricks for systems administration, engineering, and programming.
Showing posts with label replace. Show all posts
Showing posts with label replace. Show all posts
Thursday, September 10, 2009
Wednesday, May 6, 2009
vi find and replace
To perform a find and replace with all entries of a file, enter the colon to invoke ex from vi. Then, from there, enter
:%s/find_string/replace_string/g
For example:
%s/oldHostname/newHostname/g
There are many other ways to do this, but I prefer this method. This is one of the reasons that vi stands for "Voodoo for Intellectuals."
:%s/find_string/replace_string/g
For example:
%s/oldHostname/newHostname/g
There are many other ways to do this, but I prefer this method. This is one of the reasons that vi stands for "Voodoo for Intellectuals."
Subscribe to:
Posts (Atom)