I'm making a shell script to export a sqlite query to a csv file, just like this:
#!/bin/bash ./bin/sqlite3 ./sys/xserve_sqlite.db ".headers on" ./bin/sqlite3 ./sys/xserve_sqlite.db ".mode csv" ./bin/sqlite3 ./sys/xserve_sqlite.db ".output out.csv" ./bin/sqlite3 ./sys/xserve_sqlite.db "select * from eS1100_sensor_results;" ./bin/sqlite3 ./sys/xserve_sqlite.db ".exit"
When executing the script, the output apears on the screen, instead of being saved to "out.csv". It's working doing the same method with the command line, but I don't know why the shell script fails to export data to the file.
What am I doing wrong?
In SQLite, by using “. output” command we can export data from database tables to CSV or excel external files based on our requirement.
Conversion from SQLite to XLSXUpload your SQLite data (widely used in software like SQLite Database) and convert them by one click to XLSX format (widely used in software like MS Excel). Notice to XLSX format - In case your data are POINT type, then XY coordinates will be exported as well.
Instead of the dot commands, you could use sqlite3 command options:
sqlite3 -header -csv my_db.db "select * from my_table;" > out.csv
This makes it a one-liner.
Also, you can run a sql script file:
sqlite3 -header -csv my_db.db < my_script.sql > out.csv
Use sqlite3 -help
to see the list of available options.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With