LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Search number of words in vi editor at a time (https://www.linuxquestions.org/questions/linux-newbie-8/search-number-of-words-in-vi-editor-at-a-time-675429/)

sohail0399 10-10-2008 12:36 AM

Search number of words in vi editor at a time
 
hi
is it possible that i can search number of words with single command and replace them or delete them in vi editor?
or is there any code or something like that?

thanks in advance

centos82 10-10-2008 12:48 AM

I'm not sure I completely understand the question. Can you give a more specific example of what you want to do?

sohail0399 10-10-2008 01:04 AM

here is the example:
i have 3 words, eg cat, dog and hen.
I want to search these words in the file animals.txt,
I open the file vi animals.txt.
and now i want to search these 3 animals using single command or code and delete them in this file.

Mr. C. 10-10-2008 01:58 AM

Type:

Code:

/cat\|dog\|hen
and Enter

sohail0399 10-10-2008 04:00 AM

thanks!
this works
but can you tell me that after selecting how can i delete this, or replace it with in same command.

Mr. C. 10-10-2008 03:02 PM

To delete the lines containing those patterns:

:global/dog\|cat\|hen/d

To substitute those words globally for another word:

:global/dog\|cat\|hen/s//duck/g


All times are GMT -5. The time now is 10:22 AM.