Skip to content

Instantly share code, notes, and snippets.

@albertywu
Last active June 21, 2022 17:56
Show Gist options
  • Select an option

  • Save albertywu/fc3203efb493df8236a4b66b3f41acf7 to your computer and use it in GitHub Desktop.

Select an option

Save albertywu/fc3203efb493df8236a4b66b3f41acf7 to your computer and use it in GitHub Desktop.
sqlcsv - run sql on your csv
# Usage:
# sqlcsv foo.csv foo 'select count(*) from foo;'
#
# Requirement:
# brew install sqlite
function sqlcsv {
local file="$1"
local table="$2"
local cmd="$3"
sqlite3 :memory: -cmd '.mode csv' -cmd ".import $file $table" -cmd '.mode column' "$cmd"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment