Created
September 1, 2025 19:22
-
-
Save simonneutert/f71a507d67142a2d59152f917bff9654 to your computer and use it in GitHub Desktop.
mangle csv files using sq and jq
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name;group;subgroup;type | |
abc;1;a;x | |
def;2;b;y | |
ghi;3;c;z | |
jkl;4;d;x | |
mno;5;e;y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://sq.io/docs/drivers/csv#delimiters | |
sq add ./demo.csv --driver.csv.delim=semi --ingest.header | |
# https://sq.io/docs/drivers/csv#monotable | |
sq '@demo.data | .type | uniq' -j | |
# [ | |
# { | |
# "type": "x" | |
# }, | |
# { | |
# "type": "y" | |
# }, | |
# { | |
# "type": "z" | |
# } | |
# ] | |
sq '@demo.data | .type | uniq' -j | jq '{typ: [.[] | .type]}' | |
# { | |
# "typ": [ | |
# "x", | |
# "y", | |
# "z" | |
# ] | |
# } | |
sq sql 'SELECT distinct(type) from data' -j | |
# [ | |
# { | |
# "type": "x" | |
# }, | |
# { | |
# "type": "y" | |
# }, | |
# { | |
# "type": "z" | |
# } | |
# ] | |
sq sql 'SELECT distinct(type) from data' -j | jq '{typ: [.[] | .type]}' | |
# { | |
# "typ": [ | |
# "x", | |
# "y", | |
# "z" | |
# ] | |
# } | |
# write to a new csv | |
sq sql 'SELECT distinct(type) from data' --csv --output=x.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment