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

del-header removes empty cells when the input is one column #238

Closed alvanuffelen closed 9 months ago

alvanuffelen commented 1 year ago

Prerequisites

Describe your issue

csvtk del-header on one column removes the empty cells. example.txt

Empty cells are included:

cat example.txt | csvtk cut -f species

Empty cells are removed:

cat example.txt | csvtk cut -f species | csvtk del-header
shenwei356 commented 1 year ago

Hmm, they are treated as empty rows and skipped since v0.26.0.

This is problematic in your situation, I should make it optional with

 -E, --ignore-empty-row       ignore empty rows
shenwei356 commented 1 year ago

That's sad, the official csv reader skip blank lines by default, and no option to disable this.

https://pkg.go.dev/encoding/csv

Blank lines are ignored. A line with only whitespace characters (excluding the ending newline character) is not considered a blank line.

Some guys tried to change this but failed., the PR was not accepted.

shenwei356 commented 1 year ago

A workaround way: add the row number with the global flag -Z/--show-row-num, which would stop del-header removing blank lines

$ cat example.txt | csvtk cut -f species -Z | csvtk del-header | csvtk cut -f  -1 | wc -l
162

$ cat example.txt | wc  -l
163