Re: [GENERAL] Desperately Seeking Regular Expression - Mailing list pgsql-general

From Adriaan Joubert
Subject Re: [GENERAL] Desperately Seeking Regular Expression
Date
Msg-id 3725C3C3.2D9F32B0@albourne.com
Whole thread Raw
In response to Desperately Seeking Regular Expression  (Thomas Good <tomg@q8.nrnet.org>)
List pgsql-general
I solved something like this recently in perl. It's not terribly
efficient, but it is simple. I'm doing this from memory, so it may need
some debugging. Use something along the lines of

#!/usr/local/bin/perl

while (<>) {
  @a = split /(\")/;
  # This gives you a list with some of the items being double-quotes
  # Now you need to figure out which ones were inside double quotes
  my $b;
  if ($a[0] eq '"') {
    # we started with a double quoted string, so join th e 1st 3 fields
        # and stick them on the new string
    $b = join('',splice(@a,0,3))."\t";
  }
  while (@a) {
    $b .= join("\t",split(' ',shift @a))."\t";
    # if there is more then we have another double quoted string
    $b = join('',splice(@a,0,3))."\t" if @a;
  }
  # Remove the last tab and replace with a newline
  $b =~ s/\t$/\n/;
  print $b;
}

Adriaan

pgsql-general by date:

Previous
From: Andy Lewis
Date:
Subject: Re: [GENERAL] PL/pgSQL
Next
From: Tatsuo Ishii
Date:
Subject: Re: [HACKERS] Re: [GENERAL] unknown symbol 'lo_unlink'