>
> Empty fields of bad lines should be completed by fields of the
> previous good line
> that have all fields completed.
>
> foo0;bar0;foo1;bar1;foo2;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
> ;;foo1;bar1;foo2;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
> foo0;bar0;;;;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
> fooA;barA;fooB;barB;fooC;barC;fooD;barD;fooE;barE;fooF;barF;
> foo0;bar0;;;;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
>
> should be
>
> foo0;bar0;foo1;bar1;foo2;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
> foo0;bar0;foo1;bar1;foo2;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
> foo0;bar0;foo1;bar1;foo2;bar2;foo3;bar3;foo4;bar4;foo5;bar5;
> fooA;barA;fooB;barB;fooC;barC;fooD;barD;fooE;barE;fooF;barF;
> fooA;barA;fooB;barB;fooC;barC;fooD;barD;fooE;barE;fooF;barF;
First of all, it would help to have good example data, since in
your last line, it has valid values like "foo0" as the first
element that has magically changed to "fooA" in the
result-set...same with "bar5" -> "barF" as the penultimate element.
<pedant>Second, it's only vaguely a "CSV" -- those are
semi-colons instead of commas. </pedant>
That said, however, it can also be done in vim7+ with this
hideous one-liner:
:2,$g/;;/let p=split(getline(line('.')-1), ';', 1) | let
c=split(getline('.'), ';', 1) | s/.*/\=join(map(range(len(c)),
'strlen(c[v:val]) ? (c[v:val]) : (p[v:val])'), ';')
(c=current line; p=previous line)
I don't envy any person trying to deconstruct that -- it was hard
enough to assemble :) It does choke if the previous line doesn't
have enough elements to populate the current line, but that's
somewhat to be expected.
-tim
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment