How to redirect sqlite3 output to a file

Run it all as a single command:

$ sqlite3 stylish.sqlite "SELECT * FROM styles;" > somefile.txt

Example

$ sqlite3 addons.sqlite "select * from icon;" > somefile.txt

$ cat somefile.txt 
1|32|https://addons.cdn.mozilla.net/img/uploads/addon_icons/354/354399-32.png?modified=1369154804
1|64|https://addons.cdn.mozilla.net/img/uploads/addon_icons/354/354399-64.png?modified=1369154804

Using tee

If you want to see the output as it's being written to the file you can use tee instead.

$ sqlite3 addons.sqlite "select * from icon;" | tee somefile.txt
1|32|https://addons.cdn.mozilla.net/img/uploads/addon_icons/354/354399-32.png?modified=1369154804
1|64|https://addons.cdn.mozilla.net/img/uploads/addon_icons/354/354399-64.png?modified=1369154804