Monthly Archives: January 2012

Split inside specific column and expend to key-value extractor

col2kv (){    perl -F\\t -lane 'BEGIN{ $i=shift; @h=split q(,), shift; print STDERR join qq(\t), @h } %k=map { @{[split(q(:), $_)]}[0,1] } split q(, ), $F[$i]; print join qq(\t), map { $k{$_} } @h' $*} $ echo 2010Q1:H, 2007:Y, 2009:Y| col2kv … Continue reading

Posted in Uncategorized | Leave a comment

How to make group_by_in_perl?

$ typeset -f group_by_in_perlgroup_by_in_perl (){    perl -F\\t -lane 'BEGIN{$group_by=shift; $sum_by=shift} END { print for map{ join qq(\t), $_, $sum{$_}} keys %sum } $sum{join qq(\t), @F[eval($group_by)]} += $F[eval($sum_by)]' $* }

Posted in Uncategorized | Leave a comment

BJ in snowing

Posted in Uncategorized | Leave a comment