From: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Importing lines of variable length from ASCII |
Date: | 2010-02-25 11:52:19 |
Message-ID: | 20100225115219.GH16792@a-kretschmer.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
In response to Louis Becker :
> Hi
>
>
>
> I have an ASCII file that I try to import via the COPY command. The ASCII file
> is pipe delimited. Some lines in the file have no value in the last field and
> because there is no value in the last field, it also omits the last delimiter.
> It therefore seems that some lines have 11 columns while some other lines have
> 10 columns although these 10 columns correspond with the first 10 columns of
> lines that contain 11 columns. The omission of the last delimiter apparently is
> an accordance with the CSV files standard.
>
>
>
> Apart from editing the ASCII files, is there a way to import these files that
> contain lines of variable length?
Pipe your file through a filter like my example below:
kretschmer(at)tux:~$ cat file.txt
foo|bar|1|batz
bar|bla|2
this|is|3|line
kretschmer(at)tux:~$ cat file.txt | awk '{cols=split($0,a,"|"); if (cols==4) print $0; else printf ("%s|\n",$0)}'
foo|bar|1|batz
bar|bla|2|
this|is|3|line
kretschmer(at)tux:~$
Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99
From | Date | Subject | |
---|---|---|---|
Next Message | Atif Jung | 2010-02-25 17:08:03 | Leap Years |
Previous Message | Louis Becker | 2010-02-25 11:04:00 | Importing lines of variable length from ASCII |