Re: request for help with COPY syntax - Mailing list pgsql-sql

From Chuck D.
Subject Re: request for help with COPY syntax
Date
Msg-id 200710261029.56284.pgsql-list@nullmx.com
Whole thread Raw
In response to Re: request for help with COPY syntax  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
On October 25, 2007 09:22:10 pm Tom Lane wrote:
>
> Did the sed actually do anything?  (Hint: the file size of
> geonames_fixed.txt would be larger than geonames.txt if it did.
> Or you could diff the two files to confirm that something sensible
> happened.)
>
> I suspect that your shell may be fouling things up here.  You may need
> to prepare this command as a one-line shell script, using an editor that
> doesn't barf on bare carriage returns ...

Can I ask this, what is the objective here?

I have a field with ^M$ in it (shows as CR/LF in text editor).  The objective 
should be to replace the CR/LF with just a CR shouldn't it?

Or is the objective to replace the CR/LF with a literal \r?  I'm a bit 
confused by the output of COPY that says to use "\r".  Looking at other data 
in my database (user message) I'd have to say it needs to be replaced with a 
literal \r correct?

If that is the case, the sed script doesn't work because it is only replacing 
the CR and still leaves the LF which terminates a line.  I found a little 
perl to do the job of replacing the CR/LF with a literal \r

perl -p -e 's/\r\n/\\r/g' < cities.txt > cities_fixed.txt



pgsql-sql by date:

Previous
From: "Jonah H. Harris"
Date:
Subject: Re: JOINing based on whether an IP address is contained within a CIDR range?
Next
From: Thomas Kellerer
Date:
Subject: Removing whitespace using regexp_replace