Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id D7D6E9F9DE7 for ; Thu, 25 Oct 2007 18:16:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 75038-04-2 for ; Thu, 25 Oct 2007 18:16:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from pyxis.powervt.com.ar (host3.powervt.com.ar [200.43.63.66]) by postgresql.org (Postfix) with ESMTP id 300AA9F944F for ; Thu, 25 Oct 2007 18:16:40 -0300 (ADT) Received: from pcfhevia ([201.216.249.98]) by pyxis.powervt.com.ar (IPGroup Mail Server) with ESMTP id 1OT48953; Thu, 25 Oct 2007 18:16:39 -0300 From: "Fernando Hevia" To: , Subject: Re: request for help with COPY syntax Date: Thu, 25 Oct 2007 18:16:59 -0300 Organization: IP-TEL Message-ID: <043e01c8174c$61157a50$8f01010a@iptel.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcgXOz6N5VYemCrxT0G/BAlrMSHiGgAANdSw X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 In-Reply-To: <200710251313.47075.pgsql-list@nullmx.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200710/127 X-Sequence-Number: 29499 > On October 25, 2007 10:57:49 am you wrote: > > > > If all you just want to do is strip out the ^M, you can run dos2unix on > > it, assuming that you are running a *nix distro. > > Well, I guess I could strip the ^M but I'm still left with a $ in the > middle > of a field which in the same as the line terminator, so COPY thinks it is > at > the end of a line when it is really in the middle of the field. I really > wish they would have quoted these fields, but I'm at a loss how to import > these. > As I understand it when a line starts with $ you would like to merge it with the previous line. I suppose you have a file like this: --- test.txt --- this is $field1, and this is $field2 I'll create the test file: $ printf "this is \n\$field1, and this is \n\$field2\n" > test.txt (I assume ^M have already been replaced so \n are used instead) A short C program should do it: /*------ code listing -----*/ #include #include #define NL '\n' #define FILTER '$' int main(int argc, char *argv[]) { FILE *fp; char c; if (argc < 2) fp=stdin; else { fp=fopen(argv[1], "r"); if (!fp) { perror(argv[1]); exit(1); } } c=fgetc(fp); while(!feof(fp)) { if(c==NL) { c=fgetc(fp); if(feof(fp)) { putchar(NL); break; } } if(c!=FILTER) putchar(c); c=fgetc(fp); } exit (0); } /*------------------*/ compile as: $ gcc -o test test.c Execute as: $ test test.txt this is field1, and this is field2 Could this be of help? Regards, Fernando.