Re: request for help with COPY syntax

From: "Chuck D(dot)" <pgsql-list(at)nullmx(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: request for help with COPY syntax
Date: 2007-10-26 16:29:56
Message-ID: 200710261029.56284.pgsql-list@nullmx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2007-10-28 11:20:36 Removing whitespace using regexp_replace
Previous Message Jonah H. Harris 2007-10-26 12:03:25 Re: JOINing based on whether an IP address is contained within a CIDR range?