Wednesday, August 31, 2011

Re: Search and write

Thanks for help!

I want to write the digits and actually my full regex in vim is:
/[-0-9]\{13,17\}

I want numbers with 13 to 17 digits even if they have hyphens between the digits. Should then be something like:

:g/[-0-9]\{13,17\}/t.|s/[^0-9]\+//g|w! >> my.txt | d

I tried this but I get the whole text not just numerical digits (with hyphens) in a new file.

Lars




On Wed, Aug 31, 2011 at 3:44 PM, Tim Chase <vim@tim.thechases.com> wrote:
On 08/31/11 07:23, Lars Iselid wrote:
If you have a search statement something like this:

/[0-9]

And want to write :w the matching content to a file. How to do? I've
seen examples similar to this:

/[0-9] . w>>  my.txt

Depends on whether you want to write just the match, or the entire line.  If you want the entire line containing the match(es), it's pretty easy:

 g/[0-9]/w>> my.txt

If you just want to write those digits to the file, it's more complex.  Something like:

 g/[0-9]/t.|s/[^0-9]\+//g|w! >> my.txt | d

which copies each matching line to the line below, deletes all the non-digits, writes/appends the temp-line to the file, and then deletes the temp-line.

-tim



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: