Monday, 16 November 2009

 

Deleting all but first two fields in each line of a CSV File


In a csv file full of lines such
16 Prop_Description Property description, String 1000
(note that this is actually a space separated csv)

:%s#\(\d\+ \w\+\).*#\1#g

filters out all but the field number and name eg

16 Prop_Description

a regexp for normal comma separated csv would be

fred,joe,sid
"fred joe","sue","good boy

:%s/\([^,]\+\),\([^,]\+\).*/\1,\2/

Labels:


Comments:

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]