Re: [GENERAL] Desperately Seeking Regular Expression (fwd)

From: Herouth Maoz <herouth(at)oumail(dot)openu(dot)ac(dot)il>
To: Thomas Good <tomg(at)q8(dot)nrnet(dot)org>
Cc: PostgreSQL List <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] Desperately Seeking Regular Expression (fwd)
Date: 1999-04-29 13:29:08
Message-ID: l03130306b34e0b751a57@[147.233.159.109]
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

At 15:31 +0300 on 29/04/1999, Thomas Good wrote:

>
> 0) use awk to create tabs where whitespace exists as a field separator.
> 1) use perl to tr tabs back to whitespace within double quoted strings.
> 2) use sed to change "" to \N (PROGRESS nulls are idiosyncratic/idiotic)
> 3) use sed to change ? (the PROGRESS unknown value) to \N
> 4) use sed to strip the remaining single quotes

Why not do them all in perl? Why run through 4 separate steps if you are
already going through perl?

And did you mean remaining single quotes (') or remaining double quotes (")?

You can first unify steps 0 and 1. Your perl program splits by
double-quotes, and processes every second element (which indicates it's
inside the quotes). You should use the same principle, but process only the
even-numbered strings, changing spaces to tabs, not the other way around.

> foreach $elem (@ln) {
> if ( $i % 2) {
> print '"';
> $elem =~ tr/\t/ /;
> print $elem;
> print '"';
> } else {
> print $elem;
> }
> $i++;

Instead:

foreach $elem (@ln) {
if ( $i % 2) {
print '"'.$elem.'"';
} else {
$elem =~ tr/ /\t/;
print $elem;
}
$i++;

(May need modifications, especially in the initialization part, but you get
the idea).

Adding the other modifications (assuming you meant remaining double
quotes), you get something along the lines of:

foreach $elem (@ln) {
if ( $i % 2) {
if ( $elem eq "" ) {
print "\\N";
} else {
print $elem;
}
} else {
$elem =~ tr/ /\t/;
$elem =~ s/?/\\N/;
print $elem;
}
$i++;

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma

In response to

Browse pgsql-general by date

  From Date Subject
Next Message José Soares 1999-04-29 14:07:02 Re: [GENERAL] LIMIT QUESTION
Previous Message Jim Mercer 1999-04-29 13:11:08 Re: [GENERAL] 2 gig limitation?