[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: VIM command to convert comma delimited text to latex table



Vineet Kumar wrote:
> 
> * Abner Gershon (abner_gershon@yahoo.com) [020220 09:01]:
> > Can someone tell me search and replace commands I can
> > use to convert comma delimited text in form:
> > "field 1","field 2","field 3"
> > to text file to be used in tabular latex file of form:
> > field 1 & field 2 & field 3

[cut] 
 
> Be careful with the second line if you have quotation marks embedded in
> your fields, though, even if they're escaped with a backslash or
> something.

I would probably get around this by one of two ways. The first (and
simplest) way it to use 3 commands:

:%s/","/ \& /g
:%s/^"//
:%s/"$//

... in other words, change "," to &, then remove the " at the beginning
of the line and then the one at the end of the line.

The third way is to do the last 2 commands above in a single search and
replace instead:
:%s/^"\(.*\)"$/\1/

This expression means 'replace all lines starting and ending with a
quote with the contents of the quotes'.

Matthew



Reply to: