Importing .csv file to sqlite3 db table Importing .csv file to sqlite3 db table shell shell

Importing .csv file to sqlite3 db table


After much studies and discussion, I found an answer that is working properly,

echo -e ".separator ","\n.import /home/aj/ora_exported.csv qt_exported2" | sqlite3 testdatabase.db

the main thing is, that I needed to include the path of the .csv file in the import statement.


I found this to work:

(echo .separator ,; echo .import path/to/file.csv table_name) | sqlite3 filename.db

The accepted answer fails to work for me.


Why don't you take advantage of Sqlite's built-in command-line options to load CVS file to Sqlite database table? I assume you are writing bash shell script to load CSV files data to SQLite table.

Have a look on bellow single line bash script:

#!/bin/bashsqlite3  -separator "," -cmd ".import /path/to/test.csv aj_test" ajtest.db

With my limited knowladge, I can't give you any example to automatically logout sqlite cli after being load done on db!