Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a CSV file with SQL querys from linux shell

Tags:

linux

shell

sql

csv

I would like to read a CSV file from the shell as if it was an SQL Database table.

Is this possible without having to import the CSV file content to a SQL enviroment? Maybe there is some kind of linux based tool that can work it out...

I know it sounds like a tricky question, but I'm trying to avoid installing a SQL server and stuff. I have some limitations.

Any clue?

like image 472
Rorro Avatar asked Feb 25 '14 14:02

Rorro


1 Answers

Take a look at https://github.com/harelba/q, a Python tool for treating text as a database. By default it uses spaces to delimit fields, but the -d , parameter will allow it to process CSV files.

Alternatively you can import the CSV file into SQLite and then run SQL commands against it. This is scriptable, with a bit of effort.

like image 65
Richard Neish Avatar answered Nov 02 '22 00:11

Richard Neish