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 02-02-2010, 12:33 PM   #1
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Rep: Reputation: 15
How to search a string having spaces, slashes, colons in vi editor


I need to seach a string containing

the substring of 'New Request object:'

and

the substring of '/0x2ab46b1f90' in vi editor,

how do I accomplish that?

thanks.
 
Old 02-02-2010, 12:39 PM   #2
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
Vi's search string is a simplified regex parser so you simply need to escape any regex special characters which in your case is only the /.

Regards,

Alunduil
 
Old 02-02-2010, 01:44 PM   #3
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Original Poster
Rep: Reputation: 15
do I need to put quotes around the search string?

in vi, do I type

/New*Request*object:*0x2ab46b1f90

or

/'New Request object:'+'0x2ab46b1f90'
 
Old 02-02-2010, 02:31 PM   #4
alunduil
Member
 
Registered: Feb 2005
Location: San Antonio, TX
Distribution: Gentoo
Posts: 684

Rep: Reputation: 62
It would simply be /New Request object: for the first string. If you want both you'll need to use the regexp or operator: '|'. Try the following: /(item1|item2)

Although, I'm not sure if that will work as I've never encountered a time when I needed to search for multiple things I couldn't do with grep.

Regards,

Alunduil
 
Old 02-02-2010, 02:56 PM   #5
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by RajRed View Post
how do I accomplish that?
If you are trying to search for "New Request object:" and then search for the next occurrence of "/0x2ab46b1f90", you can combine two searches using syntax like
Code:
/New Request object:/;/\/0x2ab46b1f90
For more information on searching, type ":help /" in VIM.
 
Old 02-02-2010, 03:29 PM   #6
RajRed
Member
 
Registered: Mar 2005
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by David1357 View Post
If you are trying to search for "New Request object:" and then search for the next occurrence of "/0x2ab46b1f90", you can combine two searches using syntax like
Code:
/New Request object:/;/\/0x2ab46b1f90
For more information on searching, type ":help /" in VIM.
I need to search the file for a line that contains both

New Request object:

and

/0x2ab46b1f90,

how do I do that?

thanks
 
Old 02-02-2010, 04:33 PM   #7
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by RajRed View Post
I need to search the file for a line that contains both
Try
Code:
/New Request object:.*\/0x2ab46b1f90
 
Old 02-02-2010, 06:11 PM   #8
dalai lama
LQ Newbie
 
Registered: Dec 2009
Location: Amsterdam
Distribution: CentOS
Posts: 19

Rep: Reputation: 0
This command should do the trick:


Quote:
:/New Request object:.*/0x2ab46b1f90
Let me know if it worked for you
 
  


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
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 08:37 AM
search string in text and print string wolfipa Linux - Software 4 09-17-2009 09:50 AM
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 10:37 AM
How to remove spaces from a string pawan_songara Programming 14 08-30-2006 10:20 PM
spaces in a string Longinus Programming 18 03-08-2004 07:02 PM


All times are GMT -5. The time now is 02:25 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