开发者

sqlite3 output with tabs from one line command

开发者 https://www.devze.com 2023-03-16 13:31 出处:网络
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.

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消