473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How copy a new line char to a file?

Hi all,

I'm trying to copy a table with a text field column containing a new
line char to a file:

ksDesenv=# create table page(line text) without oids;
CREATE TABLE
ksDesenv=# insert into page (line)
values('1stline'||chr(10)||'2ndline');
INSERT 0 1
ksDesenv=# select * from page;
line
-----------------
1stline
2ndline
(1 registro)

ksDesenv=# copy page to '/var/www/html/kakaostats/page.txt';
COPY

But this is what the page.txt file looks like:

1stline\n2ndline

What can I do to make the copy to command insert an actual new line
char?

Regards,
Clodoaldo Pinto Neto

__________________________________________________ _____
Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! Acesse: http://br.acesso.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #1
2 4780
Hi all,

I should have explained it better:

Why don't I just insert each line in the table and let "copy to" do its
thing inserting a new line char (lf) at the end of each line?
Because I need the file lines to be in a certain order. Copy to will
copy the lines in its own order.
Until now I'm inserting html pages in a single line table without a lf
and copying then to files. Here is the result:
http://planeta.terra.com.br/informatica/kakaostats/
http://planeta.terra.com.br/informat...ts/t13802.html
Right click the page and click view source and there it is, a single
giant line.
The problem with mixing html and pl/pgsql is that it becomes a big
mess. It is very hard to evolve the code and understand it.
So I choose to not output html anymore but cvs text and build the page
with php. Advantages: much simpler pl/pgsql code and upload size 80%
smaller.
Lines finishing with a lf are much easier to parse in php (fgetcsv).
This and the need to have then ordered is why i need to insert lfs in
the single line table from which to copy to file.
I have solved it with a simple python script but it is one more step
and is not fail safe. Where there would be a lf I insert the string
"newLine". Then in the python script I change it to an actual lf char.
But in the remote possibility that there is or there will be this
string in the database (600+ thousand distinct user names) then the
output file will be wrong.
Also it is one more piece of software to be mantained.

Regards,
Clodoaldo Pinto

--- Clodoaldo Pinto Neto <cl*************@yahoo.com.br> escreveu:
Hi all,

I'm trying to copy a table with a text field column containing a new
line char to a file:

ksDesenv=# create table page(line text) without oids;
CREATE TABLE
ksDesenv=# insert into page (line)
values('1stline'||chr(10)||'2ndline');
INSERT 0 1
ksDesenv=# select * from page;
line
-----------------
1stline
2ndline
(1 registro)

ksDesenv=# copy page to '/var/www/html/kakaostats/page.txt';
COPY

But this is what the page.txt file looks like:

1stline\n2ndline

What can I do to make the copy to command insert an actual new line
char?

Regards,
Clodoaldo Pinto Neto

__________________________________________________ _____
Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade!
Acesse: http://br.acesso.yahoo.com/

---------------------------(end of
broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to
ma*******@postgresql.org


__________________________________________________ _____
Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! Acesse: http://br.acesso.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #2

On Wed, 11 Aug 2004, [iso-8859-1] Clodoaldo Pinto Neto wrote:
I should have explained it better:

Why don't I just insert each line in the table and let "copy to" do its
thing inserting a new line char (lf) at the end of each line?
Because I need the file lines to be in a certain order. Copy to will
copy the lines in its own order.
Until now I'm inserting html pages in a single line table without a lf
and copying then to files. Here is the result:
http://planeta.terra.com.br/informatica/kakaostats/
http://planeta.terra.com.br/informat...ts/t13802.html
Right click the page and click view source and there it is, a single
giant line.
The problem with mixing html and pl/pgsql is that it becomes a big
mess. It is very hard to evolve the code and understand it.
So I choose to not output html anymore but cvs text and build the page
with php. Advantages: much simpler pl/pgsql code and upload size 80%
smaller.
Lines finishing with a lf are much easier to parse in php (fgetcsv).
This and the need to have then ordered is why i need to insert lfs in
the single line table from which to copy to file.
I have solved it with a simple python script but it is one more step
and is not fail safe. Where there would be a lf I insert the string
"newLine". Then in the python script I change it to an actual lf char.
But in the remote possibility that there is or there will be this
string in the database (600+ thousand distinct user names) then the
output file will be wrong.
Also it is one more piece of software to be mantained.


I think in general you might be better off either writing functions in an
untrusted language that actually do what you want with the files or a
"client" app that connects to the database and gets the data you want and
puts it into a file. I don't think COPY TO is really meant as a general
purpose writing arbitrary content into a file tool.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Joker | last post by:
How to copy a jpg file on from local computer to remote server on the basis of PHP code?
11
by: David Morgenthaler | last post by:
How does one overide the iterator implied by the construct "for line in file:"? For example, suppose I have a file containing row,col pairs on each line, and I wish to write a subclass of file...
1
by: Neil Morris | last post by:
Hi I have the following code that lists first names of people who's surnames are 'Morris'. What I am trying to do is search for first names that don't start at the beginning of the line ie. have...
13
by: Dan V. | last post by:
How do I create a one line text file with these control codes? e.g.: 144 = 0x90 and 147 = 0x93? I am trying to create a one line text file with these characters all one one row with no spaces. ...
1
by: thesafetylemur | last post by:
Howdy, (I'm a newbie C programmer, by the way...) How would one go about reading a whole line from file? I was told that something like: fscanf("%s\n", string); but it wasn't working for me.......
11
by: elrondrules | last post by:
Hi Am pretty new to python and hence this question.. I have file with an output of a process. I need to search this file one line at a time and my pattern is that I am looking for the lines...
3
by: susinthaa | last post by:
Hi , Is there any command in perl to copy a log file from solaris machine to windows machine after telnet to that machine? After copying how can we check that log for particular event? ...
3
by: Don | last post by:
Is it possible to create a link which will cause either A) the server to serve a fresh copy of a file or B) the browser to "refresh" the copy of the file. Doing it via a link is the only...
7
by: Simon van Beek | last post by:
Dear reader, How can I make a copy from a database which is in use. If an mdb database is in use Access opens a small file with the extension ldb. This ldb file prohibits the execution...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.