Replacing multiple instances of text within a file using vi editor
Hello --
I need to replace multiple instances in a give file of the following text: Quote:
Quote:
If vi editor is not the preferred method, what would be a better way? Thanks. |
Probably something like
Code:
:s/\/usr\/lib\/nagios\/plugins/\/usr\/local\/nagios\/libexec/g Code:
:%s//usr/lib/nagios/plugins//usr/local/nagios/libexec/g |
In general, string replacement in vi is:
Code:
:%s/oldstring/newstring/g |
My preferred method would be just to use sed, and the command is still the same. Never thought of it, but sed and vi may be common code in that respect.
|
Hello --
I tried both expressions, vi and sed, but without success. When I try the vi command syntax: Quote:
Quote:
Quote:
Quote:
|
You have to delimit similar to how Sefyir shows you.
You can experiment with using double quotes. I'm unsure if they work, I know in naming files and referring to them in commands like cp and mv, using double quotes around filenames which have spaces works. But also delimiting the spaces with a backslash before them works too. Similarly, everywhere you have a forward slash which is just supposed to be a forward slash you need to delimit with a backslash before it. Any chance you can just use gedit or emacs? For me emacs, providing you have the display capabilities to support an emacs buffer window just works fine for global search and replace. You don't need regular expression formats because the editor recognizes you are within search and replace mode. I'm assuming gedit is similar to that. |
Just use an alternate delimiter (same as sed can)
Code:
:s:/usr/lib/nagios/plugins:/usr/local/nagios/libexec:g |
All times are GMT -5. The time now is 03:36 AM. |