Jorge Timón wrote:
Hi, I have a file numbers in gropus of four that i want to separate
this way:

-
0,2010
0.149036564840167          ----------------> To File A
0.174286165702154          ----------------> To File B
0.148561021969625          ----------------> To File C
0.197299757855822          ----------------> To File D
-
0,2020
0.148538114790534          ----------------> To File A
0.174768764182483          ----------------> To File B
0.152110261402346          ----------------> To File C
0.204325268521311          ----------------> To File D
-
0,2030
0.14405206434384             ...
0.172445966573654
0.157687637653766
0.203154350077063
-
...

I'm just starting to learn how to use vim, but I'm sure this
repetitive task can be managed efficiently using vim.

Though almost opaque in its terseness, my first attempt processes the whole file into its respective bits in one pass:

:g/^/if (line('.')%6>2 || !(line('.')%6)) | exec '.w! >> '.(['D', '', '', 'A', 'B', 'C'][line('.')%6]) | endif

or depending on the format, if the data lines are the only ones with periods in them (identified by the regexp "^\d\+\.") then that can be reduced to:

g/^\d\+\./exec '.w! >> '.(['D', '', '', 'A', 'B', 'C'][line('.')%6])

But is there a way to select certain lines or something similar?

I archived this email from Preben "Peppe" Guldberg (speaking of whom, I don't remember seeing him on the list recently and hope he's okay) which does something like what you describe in response to a similar question:

P> Assuming you want to keep the first and every tenth line in the buffer,
P> you could use eg.
P>
P>     :g/^/+d9
P>
P> If you want to keep every tenth line, you need a little magic:
P>
P>     :g/^/d9|m.
P>
P> Here nine lines are deleted and the tenth is moved after itself.
P> This little trick removes the tenth line from the list of lines that
P> :global processes (as does the deletion of line 2 to 9).

You might be able to adapt it for your purposes.

Any suggestion to do it faster will be appreciated.

However, if you don't want to process each case by hand, you can use my ugly stunt above that does the whole thing in one pass.

-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

To unsubscribe from this group, send email to vim_use+unsubscribegooglegroups.com or 
reply to this email with the words "REMOVE ME" as the subject.

Reply via email to