LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to search a string having spaces, slashes, colons in vi editor (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-search-a-string-having-spaces-slashes-colons-in-vi-editor-786475/)

RajRed 02-02-2010 12:33 PM

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.

alunduil 02-02-2010 12:39 PM

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

RajRed 02-02-2010 01:44 PM

do I need to put quotes around the search string?

in vi, do I type

/New*Request*object:*0x2ab46b1f90

or

/'New Request object:'+'0x2ab46b1f90'

alunduil 02-02-2010 02:31 PM

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

David1357 02-02-2010 02:56 PM

Quote:

Originally Posted by RajRed (Post 3849772)
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.

RajRed 02-02-2010 03:29 PM

Quote:

Originally Posted by David1357 (Post 3849887)
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

David1357 02-02-2010 04:33 PM

Quote:

Originally Posted by RajRed (Post 3849923)
I need to search the file for a line that contains both

Try
Code:

/New Request object:.*\/0x2ab46b1f90

dalai lama 02-02-2010 06:11 PM

This command should do the trick:


Quote:

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


All times are GMT -5. The time now is 12:17 AM.