SQLite Forum

How to dump a table to a TSV file but escape characters properly
Login
I can use the following command to dump a table into TSV format. But the problem is that when any field contains tab and newline characters, the output will be messed up. Instead, it is better to escape them as '\t' and '\n', and escape '\' as '\\'.

```
sqlite3 -readonly -header -separator $'\t' dbfile "select * from mytable;"
```

As another mode, it may be better to escape all nonprintable characters.

Does anybody have a good way to do these? Thanks.