Skip to content

Instantly share code, notes, and snippets.

@simonneutert
Created September 1, 2025 19:22
Show Gist options
  • Save simonneutert/f71a507d67142a2d59152f917bff9654 to your computer and use it in GitHub Desktop.
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.
name;group;subgroup;type
abc;1;a;x
def;2;b;y
ghi;3;c;z
jkl;4;d;x
mno;5;e;y
# 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