shenwei356 / csvtk

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

How to escape a comma in an column name? #141

Closed poolfactory closed 3 years ago

poolfactory commented 3 years ago

Hello shenwei365,

i have a CSV which has commas in some column names and I guess they are causing problems when using cut -f.

How could I escape a comma in a column name like this:

cut -f "Hi, there"

csvtk 0.23.0 on Windows. Delimiter is ,

Real life example: The following command fails with "System could not find the indicated file"

csvtk cut "source.csv" -f ID,Typ,Artikelnummer,Name,Veröffentlicht,"Ist hervorgehoben?","Sichtbarkeit im Katalog","Datum, an dem Angebotspreis beginnt","Datum, an dem Angebotspreis endet","Vorrätig?","Gewicht (kg)",Angebotspreis,"Regulärer Preis","Übergeordnetes Produkt" -C "" -I -o "destination.csv"

Thank you for advice. Great piece of software!

shenwei356 commented 3 years ago

please use double quotation marks for patterns containing any comma, e.g., -p '"A{2,}"'

For column Hi, there, it can be

csvtk cut -f '"Hi, there"'

Or

csvtk cut -f "\"Hi, there\""

But on Windows, I tested and failed.

Besides, for your file, it would need a lot of manually typing. I'd like to suggest you to edit or rename the column names in a text editor or Excel.

Or you can use numeric indexes for selecting, before that, you may use csvtk headers to check the column names and their column numbers.