Friday, 8 July 2011

Vi - Substitute Word

Sometimes it is necessary to replace a word with a new word. Vi gives you the option to do this without having to manually go through searching for each occurence of the word individually.

For example, you wish to update a pfile for a database TEST to be used for database DEV. You would use the following command:
$ vi initTEST.ora
(From within VI perform the next steps:)
:1,$ s/TEST/DEV/gc

What the Code Means:

:
- in vi this allows you to enter a command
1,$
- perform this command wherever you see the word to replace
s
- substitute command
/TEST/
- match word, the /tells Vi the beginning of the word is to follow, the / tells vi that the word has ended.
DEV/
- text to replace with
g
- change every occurance on the line not just the first one, this is the global flag
c
- ask before committing, this allows you to confirm you wish each occurance to be changed as vi picks it up.

No comments:

Post a Comment

Please feel free to leave a comment