Wednesday, August 26, 2009

Re: Correcting malformed csv

On Wed, Aug 26, 2009 at 2:06 PM, Tim Chase <vim@tim.thechases.com> wrote:

> Ugh...horrible application.  I haven't banged against the edge
> cases on this, but for fairly "clean" source data, you might try
> the following:
>
> :%s/\%(^\|,\)"\zs.\{-}\ze"\%($\|,\)/\=substitute(submatch(0),'"',
> '""','g')/g
>
> It may fail on pathological cases where you have a string like
>
>  ...,"She said "hello", to me",...
>
> because of the comma-after-the-quote (the regexp doesn't check
> for internal quote-parity) but otherwise, it should knock out the
> worst offenders so you can focus on the pathological that may remain.

Thanks. That took care of most of it. I did have a few of those
pathological cases, but I'm more than 90% there. I think I understand
most of the regex, but I'm not familiar with the \%. Looking through
the help didn't help me understand this particular usage.

-- Jay

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

No comments: