Created
September 11, 2015 00:58
-
-
Save dahu/cdc0aba6133309f45d24 to your computer and use it in GitHub Desktop.
Collapse key\tvalue pairs into key\tvalue1,value2,...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Barry Arthur Sep 2015 | |
" Convert possibly repeating key\tvalue pairs into key\tvalue1,value2,... | |
function! CollapsePairs() | |
let stuff = {} | |
g/\t/let pair = split(getline('.'), '\t') | let stuff[pair[0]] = add(get(stuff, pair[0], []), pair[1]) | d | |
call append('$', map(sort(items(stuff)), 'v:val[0] . "\t" . join(v:val[1], ",")')) | |
endfunction | |
call CollapsePairs() | |
finish | |
one apple | |
one pear | |
three moon | |
two elephant | |
one lemon | |
two pig | |
two tiger | |
zero chair |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment