Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active July 7, 2016 05:34
Show Gist options
  • Save nepsilon/9e0cea474f220161becfe883b31bba07 to your computer and use it in GitHub Desktop.
Save nepsilon/9e0cea474f220161becfe883b31bba07 to your computer and use it in GitHub Desktop.
Need to make sense of large CSV files? — First published on fullweb.io issue #44

Need to make sense of large CSV files?

Often you are handed-out big CSV files and need to sort, filter, update some cells or other tedious work. You tried sed, jq, and maybe the mighty awk.

But at the end of the day: You’re using the wrong tool for the job.

Here come csvkit’s csvsql, a small Python script to parse your CSV files and create the corresponding database. You now have the best tool, SQL, to answer your data questions:

# Output CREATE TABLE statement
# Here for SQLite:
csvsql -i sqlite data.csv 

# Create the DB and insert the data:
csvsql --db sqlite:///data.db --insert data.csv 

# And if you just want to run a single query
# no need to create the DB, just run:
csvsql --query "your query here" data.csv | csvlook
# csvlook will prettify the output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment