LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-11-2009, 05:13 AM   #1
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 283

Rep: Reputation: 32
searching multiple patterns through Vi editor


Hi,
I want to find multiple patterns through vi editor.
For example, suppose we need to find pattern1 or pattern2 in file file-name.

The equivalent command in egrep
$ egrep 'pattern1|patteren2' file-name

Is there a way to find multiple patterns through vi editor ?

I could not find multiple patterns using /pattern1|pattern2.


With Thanks in advance,
Barun Parichha
 
Old 05-11-2009, 05:19 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

You need to escape the pipe when using vi:

/pattern1\|patteren2 will do the trick.

Hope this helps.
 
Old 05-11-2009, 05:46 AM   #3
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 283

Original Poster
Rep: Reputation: 32
Hi drunna,
The above trick did not work.
 
Old 05-11-2009, 05:52 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

I was initially confused by "file-name" but assumed you are 'just' looking for one or both patterns in a specific file using vi(m).

What is it you are actually trying to do? Your example talks about vi (which shows a body of text, which can be searched) and (e)grep, which looks thru multiple files for a certain string.
 
Old 05-11-2009, 06:21 AM   #5
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 283

Original Poster
Rep: Reputation: 32
Assume that in both the cases I am searching pattern1 or pattern2 from some file file-name. The file-name is just the name of the file to be searched.
 
Old 05-11-2009, 07:21 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Ok,

Then my solution does work: Open fileX with vi(m), search for pattern1 or pattern2: /pattern1\|pattern2.

The cursor will go to the first pattern it finds (either pattern1 or pattern2) and if highlight search (set hlsearch) is active all the found patterns will be highlighted in the visible text.

If that is not what you want, please elaborate.
 
Old 05-12-2009, 02:09 AM   #7
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 283

Original Poster
Rep: Reputation: 32
You are right, I need to search pattern1 or pattern2. But your solution did not work in Vi. I am using Vi in Solaris.
 
Old 05-12-2009, 02:57 AM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Show us the exact cmd you tried in vi (and example file); it worked for me

:/patt1\|patt2
 
Old 05-12-2009, 03:13 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
@chrism01: The OP is using vi, not vim. I do believe that my solution only works when using vim.
 
Old 05-12-2009, 04:54 AM   #10
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 283

Original Poster
Rep: Reputation: 32
Hi chrism01 and drunna,
I have clearly mentioned in my previous post that
:/pattern1\|pattern2 did not work under Vi.

Did any of you get success through Vi ?

Barun
 
Old 05-12-2009, 08:39 PM   #11
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
I'd be a little surprised if that didn't work in vi as well, but I don't have access to vi. Just checked the CENTOS repo and there's no vi(!) so I can't download/try it.
I am surprised about that...
 
  


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
grep for multiple patterns???? lucastic Linux - Software 4 08-06-2010 06:07 PM
If condition for checking patterns in multiple files rattlesnakejoe Programming 5 05-07-2009 02:52 AM
searching for redundant patterns adidassharma Programming 5 09-26-2008 12:35 AM
Remembering patterns and printing only those patterns using sed bernie82 Programming 5 05-26-2005 05:18 PM
Searching patterns from file MichaelVaughn Programming 1 04-06-2004 11:18 AM


All times are GMT -5. The time now is 02:19 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration