dosql - run sql commands on tabular text files
TRANSCRIPT
![Page 1: doSQL - Run SQL commands on tabular text files](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/1.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/2.jpg)
I’m a data guy.I’m a data guy.
![Page 3: doSQL - Run SQL commands on tabular text files](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/3.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/4.jpg)
I also love SQL.I also love SQL.
![Page 5: doSQL - Run SQL commands on tabular text files](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/5.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/6.jpg)
... 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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/7.jpg)
So i wrote doSQL.py.So i wrote doSQL.py.
![Page 8: doSQL - Run SQL commands on tabular text files](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/8.jpg)
>> 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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/9.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/10.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/11.jpg)
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](https://reader035.vdocuments.us/reader035/viewer/2022062308/55b54751bb61eb33178b45b9/html5/thumbnails/12.jpg)
Enjoy!Enjoy!The code can be found in githubThe code can be found in github
https://github.com/wishvamalli/doSQL