12
doSQL a command line script to run SQL on text files. @wishvamalli

doSQL - Run SQL commands on tabular text files

Embed Size (px)

Citation preview

Page 1: doSQL - Run SQL commands on tabular text files

doSQLdoSQLa command line script to run SQL on text files.

@wishvamalli

a command line script to run SQL on text files.

@wishvamalli

Page 2: doSQL - Run SQL commands on tabular text files

I’m a data guy.I’m a data guy.

Page 3: doSQL - Run SQL commands on tabular text files

I spend most of my time on the command line, I spend most of my time on the command line, working with text data files.working with text data files.

Page 4: doSQL - Run SQL commands on tabular text files

I also love SQL.I also love SQL.

Page 5: doSQL - Run SQL commands on tabular text files

But the sad thing is that there is no simple way to But the sad thing is that there is no simple way to directly execute SQL on a text file...directly execute SQL on a text file...

Page 6: doSQL - Run SQL commands on tabular text files

... without manually importing the text to a ... without manually importing the text to a database...database...

and that’s boring!and that’s boring!

Page 7: doSQL - Run SQL commands on tabular text files

So i wrote doSQL.py.So i wrote doSQL.py.

Page 8: doSQL - Run SQL commands on tabular text files

>> python doSQL.py --one data.txt --sql “SELECT * from one”>> python doSQL.py --one data.txt --sql “SELECT * from one”

now you can do...now you can do...

and also pipe the data to another command.and also pipe the data to another command.

>> python doSQL.py --one data.txt --sql “SELECT * from one” | head>> python doSQL.py --one data.txt --sql “SELECT * from one” | head

Page 9: doSQL - Run SQL commands on tabular text files

doSQL simply takes your data file and adds it to a doSQL simply takes your data file and adds it to a SQLite3 database saved in memory.SQLite3 database saved in memory.

Then it will execute your SQL and print the results.Then it will execute your SQL and print the results.

Page 10: doSQL - Run SQL commands on tabular text files

So any standard SQL statement would work.So any standard SQL statement would work.Including joins! Including joins!

(use --two to specify the second file).(use --two to specify the second file).

Page 11: doSQL - Run SQL commands on tabular text files

And as SQLite comes with python all you need is a And as SQLite comes with python all you need is a basic python installation on any OS, and you are basic python installation on any OS, and you are

good to go!good to go!

Page 12: doSQL - Run SQL commands on tabular text files

Enjoy!Enjoy!The code can be found in githubThe code can be found in github

https://github.com/wishvamalli/doSQL