I want to have my sqlite3 output separated by tabs. The -column option does not suit me because separate records with spaces and my values ha开发者_C百科ve spaces but no tabs.
If I use interactively sqlite3 I can use .mode tab
. The one-line command has the option -separator but I don't know how to add a tab there that gets interpreted as a tab not literal (probably with and ASCII code?)
Any suggestions? All the google examples that I found was for interactive sqlite3.
At the moment I am using the brute force approach:
sqlite3 -header mydb "select * from table1" | tr \| '\t' > myoutput
This should work:
sqlite3 -separator $'\t' -header mydb "select * from table1"
The $ tells your shell to expand to a tab character.
You can directly use .mode tab
when using sqlite in a shell script (for example) by using a here document like:
sqlite3 -header mydb <<EOF
.mode tabs
select * from table1;
EOF
This works on both Linux and Windows:
sqlite3 -header -cmd ".mode tabs" mydb "select * from table1"
精彩评论