Export from sqlite to csv using shell script

前端 未结 5 1575
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 09:54

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/sq         


        
5条回答
  •  眼角桃花
    2020-11-27 10:43

    sqlite3

    You have a separate call to sqlite3 for each line; by the time your select runs, your .out out.csv has been forgotten.

    Try:

    #!/bin/bash
    ./bin/sqlite3 ./sys/xserve_sqlite.db <

    instead.

    sh/bash methods

    You can either call your script with a redirection:

    $ your_script >out.csv
    

    or you can insert the following as a first line in your script:

    exec >out.csv
    

    The former method allows you to specify different filenames, while the latter outputs to a specific filename. In both cases the line .output out.csv can be ignored.

提交回复
热议问题