Re:Csvlens: Command line CSV file viewer. Like less but made...
by cowsandmilk on Saturday January 06, 2024 @08:53AM
(#38891426)
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.
Re:Csvlens: Command line CSV file viewer. Like less but made...
by prudentpomelo on Saturday January 06, 2024 @11:38AM
(#38892821)
Awk now supports a `--csv` flag for processing csv's. https://github.com/onetrueawk/awk/blob/master/README.md
Re:Csvlens: Command line CSV file viewer. Like less but made...
by musha68k on Saturday January 06, 2024 @11:41AM
(#38892842)
oh nice TIL
Re:Csvlens: Command line CSV file viewer. Like less but made...
by snidane on Saturday January 06, 2024 @01:51PM
(#38894070)
How does one output properly csv quoted rows? It seems thr csv flag works only for parsing inputs.
Re:Csvlens: Command line CSV file viewer. Like less but made...
by musha68k on Saturday January 06, 2024 @11:09AM
(#38892566)
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
awk -v OFS='\t' '{$1=$1; print}' | column -t