shenwei356 / csvtk

A cross-platform, efficient and practical CSV/TSV toolkit in Golang
http://bioinf.shenwei.me/csvtk
MIT License
992 stars 84 forks source link

Counting unique text occurences without empty cells #237

Closed alvanuffelen closed 1 year ago

alvanuffelen commented 1 year ago

Prerequisites

Describe your issue

Is there a way to count unique text occurrences in a column without counting empty cells? example.txt

cat example.txt | csvtk summary -f order:countuniq,family:countuniq,genus:countuniq,species:countuniq
order:countuniq,family:countuniq,genus:countuniq,species:countuniq
29,35,43,94
shenwei356 commented 1 year ago

Oh, it's not supported. A work around solution:

for rank in order family genus species; do
    echo -ne “rank,$(csvtk cut -f $rank example.txt | csvtk uniq -f $rank | csvtk grep -r -v -p ^$ | csvtk nrows)\n";
done
alvanuffelen commented 1 year ago

Thanks, that worked! Although, I had to change “rank to "$rank