« eBay Global EasyBuy India Review - Deterioration In Service | Main
Adding in a CSV file using Vim
November 3, 2010
Adding together numbers in csv file (when numbers are in the last column)
First define function in C:\Program Files (x86)\Vim\vim73\plugin (or similar) directory (eg add.vim) with the following:
let g:S = 0 "result in global variable S
function! Sum(number)
let g:S = g:S + a:number
return a:number
endfunction
Then execute the following (can be yanked into a buffer and executed)
:let S=0
:%s/,\zs\d\+\(\.\d\)\?\d\?$/\=Sum(submatch(0))/g
:echo S
Note that this method ignores decimal points for taking the sum. That is 11.75 + 12.32 = 23
Posted by liveit at November 3, 2010 2:52 AM
