BurntSushi / xsv

A fast CSV command line toolkit written in Rust.
The Unlicense
10.29k stars 317 forks source link

Any way to handle a comma in a header? #288

Open chris-herring opened 2 years ago

chris-herring commented 2 years ago

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

datatraveller1 commented 2 years ago

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

hbina commented 2 years ago

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