LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2008, 01:36 AM   #1
sohail0399
Member
 
Registered: Oct 2008
Location: Pakistan, Islamabad
Distribution: CentOS, Fedora, Solaris
Posts: 154

Rep: Reputation: 23
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
 
Old 10-10-2008, 01:48 AM   #2
centos82
Member
 
Registered: Sep 2008
Distribution: CentOS
Posts: 75

Rep: Reputation: 16
I'm not sure I completely understand the question. Can you give a more specific example of what you want to do?
 
Old 10-10-2008, 02:04 AM   #3
sohail0399
Member
 
Registered: Oct 2008
Location: Pakistan, Islamabad
Distribution: CentOS, Fedora, Solaris
Posts: 154

Original Poster
Rep: Reputation: 23
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.
 
Old 10-10-2008, 02:58 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Type:

Code:
/cat\|dog\|hen
and Enter
 
Old 10-10-2008, 05:00 AM   #5
sohail0399
Member
 
Registered: Oct 2008
Location: Pakistan, Islamabad
Distribution: CentOS, Fedora, Solaris
Posts: 154

Original Poster
Rep: Reputation: 23
thanks!
this works
but can you tell me that after selecting how can i delete this, or replace it with in same command.
 
Old 10-10-2008, 04:02 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grepping 'how many words have x number of characters' dtat651 Linux - Newbie 17 07-28-2008 12:24 AM
counting the words in vi editor. dina3e Linux - Software 6 07-16-2008 11:09 PM
Search logfiles for specific words kinetik Linux - General 2 03-29-2006 08:04 PM
nice egrep 300 search words in one go? shalomajay LinuxQuestions.org Member Intro 2 03-01-2006 06:31 PM
Search and Replace: Asian Words to English Words ieeestd802 Linux - Software 0 10-27-2004 08:48 PM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration