4 ms·
I'd go further and say don't parse CSV with plaintext tools because it's barely a plaintext format. Use a CSV library and save yourself heartache when someone d
by XorNot 5y ago
I'd go further and say don't parse CSV with plaintext tools because it's barely a plaintext format. Use a CSV library and save yourself heartache when someone drops a quoted string in somewhere.
- oblio 5y agoI don't understand why you're being downvoted. Parsing CSV with simple text-oriented tools is bad of an idea as parsing HTML with regexps.
- devenvdev 5y agoMost likely because it contradicts most people's experience, some CSVs can't be parsed with cli tools, but most of them can be, and it's much easier than writing code that does the same. So what the parent commenter says is true, just not pragmatic.
- oblio 5y agoIt is pragmatic with a minor tweak. https://csvkit.readthedocs.io/en/latest/ https://csvkit.readthedocs.io/en/latest/ https://github.com/BurntSushi/xsv https://github.com/BurntSushi/xsv Heck, even sqlite has some stuff to help with processing CSV files: https://www.sqlite.org/csv.html https://www.sqlite.org/csv.html
- philwelch 5y agocsvkit and SQLite were always too slow whenever I tried to use them for this sort of thing. I don’t remember if I tried xsv. I do think I ended up converting most of my CSVs to TSV, or exporting them as TSV in the first place.
- ryanianian 5y agoThis isn't parsing CSV, it's generating it. That's not nearly as fraught.
- philwelch 5y agoIn my experience doing this kind of thing, I usually use TSV instead of CSV and end up using Unix tools anyway. None of the CSV tools keep up in terms of performance.