Skip site navigation (1) Skip section navigation (2)

Re: Importing lines of variable length from ASCII

From: Andrej <andrej(dot)groups(at)gmail(dot)com>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Importing lines of variable length from ASCII
Date: 2010-02-25 20:35:59
Message-ID: (view raw or whole thread)
Lists: pgsql-novice
On 26 February 2010 00:52, A. Kretschmer
<andreas(dot)kretschmer(at)schollglas(dot)com> wrote:
> kretschmer(at)tux:~$ cat file.txt | awk  '{cols=split($0,a,"|"); if (cols==4) print $0; else printf ("%s|\n",$0)}'

Slightly shorter variant:
awk -F'|' '{if(NF<4){print $0"|"}else{print $0}}' file.txt

> Regards, Andreas


Please don't top post, and don't use HTML e-Mail :}  Make your quotes concise.

In response to


pgsql-novice by date

Next:From: Mary AndersonDate: 2010-02-26 01:11:41
Subject: How many columns can I have in an ORDER BY clause?
Previous:From: Andreas KretschmerDate: 2010-02-25 18:18:26
Subject: Re: Leap Years

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group