The generic tool recommendation question: unix.stackexchange.com/questions/7425/is-there-a-robust-command-line-tool-for-processing-csv-files
Lots of features, but slow because written in Python. A faster version may be csvtools. Also some annoyances like obtuse header handing and missing features like grep + cut in one go: csvgrep and select column in csvkit.
Simple example:
output:
printf '00,11,22\n33,44,55\n' | csvgrep -H -c2 -r '^11$' | tail -n+2
00,11,22
More verbose description:
There seems to be no way without a pipe, you seem to need to reparse the columns, e.g. the tutorial at: csvkit.readthedocs.io/en/latest/tutorial/2_examining_the_data.html#csvgrep-find-the-data-you-need does:
csvcut -c county,item_name,total_cost data.csv | csvgrep -c county -m LANCASTER
A compiled executable under
/usr/bin/csvtool
, has an Ubuntu 23.04 package: manpages.ubuntu.com/manpages/lunar/en/man1/csvtool.1.htmlThere seems to be no sane filtering mechanism however: stackoverflow.com/questions/46540752/using-csvtool-call-to-filter-csv-in-bash
Build failed with
undefined reference to pcre_config
on Ubuntu 23.04: github.com/DavyLandman/csvtools/issues/18Unfortunately it is lacking some basic options, like optional header + selecting column by index on
csvgrep
(though csvcut
has it). The project seems kind of dead.Also unclear if it allows to filter + print only selected columns.
Is this the one?
The fact that you cannot have trailing commans in lists or dicts as in
is one of the most infuriating design choices of all time!!!
3,
at:
{
"asdf": [
1,
2,
3,
]
}
echo '[{"a": 1, "b": 2}, {"b": 3}]' | jq '.[] | select(.a) | .a'
1
Bibliography:
Do you know what is worse than XML? Pseudo XML: stackoverflow.com/questions/5558502/is-html5-valid-xml/39560454#39560454
XML predecessor.
SGML predecessor.
XPath kind of died with the rise of CSS selectors around the beginnning of the 2010's. But that is a shame. XPath is a good standard, and was generally more powerful than CSS selectors for many many years.
Articles by others on the same topic
There are currently no matching articles.