xsv icon indicating copy to clipboard operation
xsv copied to clipboard

Any way to handle a comma in a header?

Open chris-herring opened this issue 3 years ago • 2 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

chris-herring avatar Dec 18 '21 04:12 chris-herring

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

datatraveller1 avatar Feb 15 '22 14:02 datatraveller1

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

hbina avatar Mar 08 '22 04:03 hbina