BurntSushi / xsv

A fast CSV command line toolkit written in Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any way to handle a comma in a header?

chris-herring opened this issue · comments

For example given the following CSV data (from a survey)

Name,"Do you consider yourself to have a disability, impairment or long-term condition?"
Ben,Yes
Phil,No

This command fails:

.\xsv.exe select Name,"Do you consider yourself to have a disability, impairment or long-term condition?" test.csv

This works for me on MS Windows (quoting 4 times):
.\xsv.exe select Name,""""Do you consider yourself to have a disability, impairment or long-term condition?"""" test.csv

You need to escape the double quotes like so,

hbina@akarin ~/D/test-xsv> cat select_test.csv 
Name,"Stringly header"
Ben,Yes
Phil,No⏎                                                                                                                                                                                                                    
hbina@akarin ~/D/test-xsv> xsv select Name,"\"Stringly header\"" select_test.csv
Name,Stringly header
Ben,Yes
Phil,No