dbro / csvquote

Enables common unix utlities like cut, awk, wc, head to work correctly with csv data containing delimiters and newlines
MIT License
446 stars 24 forks source link

working with body #7

Closed ppKrauss closed 9 years ago

ppKrauss commented 9 years ago

To work with datasets as country-codes.csv we need some more workaround. The simple "sort by column3" is,

cat country-codes.csv | (read -r; printf "%s\n" "$REPLY"; csvquote | sort -t , -k 3,3 | csvquote -u) > byCol3.csv

So, perhaps you can build a shell complement to work in a simple syntax, as csvsort command.


PS: I have problems with csvkit, and, as suggested here back to usual unix commands... But need simple command, as suggested here (but not works fine and I using this ugly).

dbro commented 9 years ago

If I understand you correctly, the first line of the data file country-codes.csv contains the labels of the fields, and you would like your output file to keep that as the first line. The remaining lines would be sorted by the value in the 3rd field.

The command you suggest is a good one. It's an appropriate solution that composes various unix shell commands, not what I would call a "workaround." You could create a wrapper around this compound command, following the example shown by the csvheader script in this repository. However I don't think it's necessary to include a script specifically for the use case you describe in this repository. The aim of csvquote is to do one thing, and to be ready to work with other unix commands as you've demonstrated.