How to export the matches only in a pattern search in vim?

Posted by Mert Nuhoglu on Stack Overflow See other posts from Stack Overflow or by Mert Nuhoglu
Published on 2010-06-13T09:44:00Z Indexed on 2010/06/13 9:52 UTC
Read the original article Hit count: 262

Filed under:
|
|

Is there a way to grab and export the match part only in a pattern search without changing the current file?

For example, from a file containing:

57","0","37","","http://www.thisamericanlife.org/Radio_Episode.aspx?episode=175"
58","0","37","","http://www.thisamericanlife.org/Radio_Episode.aspx?episode=170"

I want to export a new file containing:

http://www.thisamericanlife.org/Radio_Episode.aspx?episode=175
http://www.thisamericanlife.org/Radio_Episode.aspx?episode=170

I can do this by using substitution like this:

:s/.\{-}\(http:\/\/.\{-}\)".\{-}/\1/g
:%w>>data

But the substitution command changes the current file. Is there a way to do this without changing the current file?

© Stack Overflow or respective owner

Related posts about regex

Related posts about vim