Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert data from files into SQLite database

I have an SQLite database on this form:

Table1

Column1 | Column 2 | Column 3 | Column 4

I want to populate this database with data stored in some hundred .out files in this form, where every file has millions of rows:

value1;value2;value3;value4;
2value1;2value2;2value3;2value4;
... etc

Is there a fast way to populate the database with these data? One way would be to read in the data line for line in python and insert, however there probably should be a faster way to just input the whole file?

Bash, SQLite, Python preferrably

like image 939
bjornasm Avatar asked Apr 22 '26 20:04

bjornasm


1 Answers

SQLite has a .import command.

.import FILE TABLE Import data from FILE into TABLE

You can use it like this (shell).

for f in *.out
do
    sqlite3 -separator ';' my.db ".import $f Table1"
done