back

by musha68k·2y ago·view on hn ↗
Not on “computer” but some such in your pipeline should be good enough more often than not?

awk -v OFS='\t' '{$1=$1; print}' | column -t

1 comments
many csv data sets cannot be handled by awk due to csv supporting things like commas inside fields, newlines inside fields, etc. Your solution would also fall over for any tabs within fields. Plenty of tools out there support RFC 4180 CSV files as well as common csv variants. And these tools have been around for a decade and have suites of cli commands that can be piped together, just speaking "CSV" as a format rather than pure text streams.
Awk now supports a `--csv` flag for processing csv's. https://github.com/onetrueawk/awk/blob/master/README.md
How does one output properly csv quoted rows? It seems thr csv flag works only for parsing inputs.
oh nice TIL
Good points on using proper CSV tooling 100%; so that’s why the disclaimer “more often than not”

BTW I just realized that I was omitting the field separator ‘-F,’ actually.

For those pesky nested commas from top off simplistic text hat still I’d go back to sed for fun and potential profit:

sed 's/","/"\t"/g; s/^"/"\t/; s/"$//; s/,,/, ,/g' | column -t

Not elegant nor hands-off and might be missing something else; def needs the right data / volume and fiddling as we know ymmv; can get unwieldy quickly etc etc

TLDR; use column -t when applicable