Under windows:

SQLite version 3.7.9 2011-11-01 00:52:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t(a,b);
sqlite> insert into t values(1,2);
sqlite> insert into t values(3,4);
sqlite> .output akk.txt
sqlite> select * from t;
sqlite> .output stdout
sqlite> .quit

od -x akk.txt
0000000 7c31 0a32 7c33 0a34
0000010

LF only -- no CR.

So the output won't be happy under notepad.  Wordpad would work fine though on 
the file.  After which you save it from Wordpad and you'll have the CR/LF.
od -x akk.txt
0000000 7c31 0d32 330a 347c 0a0d


Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Advanced GEOINT Solutions Operating Unit
Northrop Grumman Information Systems



From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Kees Nuyt [k.n...@zonnet.nl]
Sent: Monday, May 14, 2012 2:03 PM
To: sqlite-users@sqlite.org
Subject: EXT :Re: [sqlite] how to write line feed "\n\r" when output a txt file


On Mon, 14 May 2012 05:41:08 +0000, YAN HONG YE <yanhong...@mpsa.com>
wrote:

>when I use :
>
>.output akk.txt
>select * from dhq where qph>0;
>.output stdout
>
> command to write a txt file,I found no "\n\r" in the each line,

Are you sure?

By the way, common lineendings are platform dependent

MS Windows: \r\n  = 0x0D 0x0A = cr lf
Unix/Linux: \n    = 0x0A = lf
Apple  Mac: \r    = 0x0D = cr

As far as i know, using
        \n\r  = 0x0A 0x0D = lf cr
is very very rare. In fact I only saw it on the console interface of a
DATUS portselector, back in the 1980s.

> how to write "\n\r" each line in the output txt file?

Pipe it through awk, for example (Unix/Linux):

printf "select * from dhq where qph>0;\n" \
| sqlite3 your.db \
| awk '{printf "%s\r\n",$0}' \
>akk.txt

In awk on MS Windows, "\n" will render "\r\n", except when BINMODE is
used.

Many programs are able to cope with several different line endings, but
indeed notepad insists on \r\n.

Hope this helps.

--
Regards,

Kees Nuyt

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to