On Sun, Aug 15, 2010 at 5:58 PM, Simon Slavin <slav...@bigfraud.org> wrote: > > On 15 Aug 2010, at 11:31pm, Peng Yu wrote: > >> $ cat file.txt >> 1 eenie >> 2 meenie >> 3 miny >> 4 mo >> $cat main.sql >> #!/usr/bin/env bash >> >> rm -f main.db >> sqlite3 main.db < file.txt <<EOF > > That cannot work: it would require a file with commands in and your file has > data in.
Now, I understand. It is because both the input file and the here document use the same stdin. I'll have to use the .read command like the following. Then the problem is solved. Thank you for everybody that helped me! $ cat main.sql create table test (id integer primary key, value text); .separator "\t" .import /dev/stdin test .headers on .mode column select * from test; $ cat main.sh #!/usr/bin/env bash rm -rf main.db cat file.txt | sqlite3 main.db '.read main.sql' $ cat file.txt 1 eenie 2 meenie 3 miny 4 mo $ ./main.sh id value ---------- ---------- 1 eenie 2 meenie 3 miny 4 mo >> create table test (id integer primary key, value text); >> .separator "\t" >> .import /dev/stdin test >> >> .headers on >> .mode column >> select * from test; >> >> EOF > > Some of those lines are commands to your Unix shell and others are commands > for the sqlite3 program. You cannot mix a shell script and SQL commands like > that. Try these three files: > > $ cat file.tsv > 1 eenie > 2 meenie > 3 miny > 4 mo > > $cat importfile.sql > create table test (id integer primary key, value text); > .separator "\t" > .import file.tsv test > .headers on > .mode column > select * from test; > > $cat importfile > #!/usr/bin/env bash > rm -f main.db > sqlite3 main.db '.read importfile.sql' > > I have not tested this, but it should point you in the right direction. > > Simon. > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Regards, Peng _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users