tags:

views:

255

answers:

2

I am trying to extract the string from a file having following pattern within a line

>------ </

The ----- represents can be any variable length string. The start pattern within a line is > and end pattern </.

Using regex of VIM is command line search possible? and if so could that be printed?

Or will have to write a script?

I am a new user to VIM

+4  A: 

Try the following vim search:

/">\(.*\)<\/

That should match any line with that pattern. It'll also store whatever text it grabs in between your start and end markers into \1 which you can use if you want to do search and replace in vim. For example:

:%s/">\(.*\)<\//Log message: \1/

If you want to use grep in the command line to search for that string you can use:

$ egrep "\">.*<\/" foo.txt

This will print out only the matching lines from foo.txt. If you want to send these to a new file try:

$ egrep "\">.*<\/" foo.txt > new.txt
Devrin
I need the highlighted text only to stay and rest all data should get deleted or whatever text grabbed could that be redirected to any other file?
kadeshpa
Probably one more non-greedy solution?
Mykola Golubyev
Why the leading doublequote?
rampion
+1  A: 

Try this

%:s/.*>\(.*\)<\/.*/\1/
Mykola Golubyev