Re: AWK script

From: Atif Jung <atifjung(at)gmail(dot)com>
To: glenn <glenn(at)davy(dot)net(dot)au>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: AWK script
Date: 2010-04-13 14:41:05
Message-ID: k2ld1c6b9c51004130741q503384a9rb88b6e77ee4a1d9e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Sorry Glenn, I should have made it clear, when I said 'var[x,y]' is
completely variable I meant the whole string, so it could look like:

var[x,y]
:h_def[x,y]
hello[x,y]

and so on ....

I've managed to do the match ok using

/ORDER BY [A-za-z0-9_:]*\[[0-9]*,[0-9]*\]/

this seems to work, but I'm still working on what I would write for the
second parameter for the gsub function.

Thanks
Atif

On 13 April 2010 15:02, glenn <glenn(at)davy(dot)net(dot)au> wrote:

> Hi Atif
> from one non expert to another, does this help:
>
> glenn(at)baldur:~$ cat x
> ORDER BY var[x,y]
> ORDER BY var[2,5]
> ORDER BY var[Z,Q]
> ORDER BY var[ABC,DEF]
>
> glenn(at)baldur:~$ sed 's/ORDER\ BY\ var\[\(.*\),\(.*\)\]/ORDER\ BY\
> SUBSTRING(var\ FROM\ \1\ FOR\ \2\)/' x
> ORDER BY SUBSTRING(var FROM x FOR y)
> ORDER BY SUBSTRING(var FROM 2 FOR 5)
> ORDER BY SUBSTRING(var FROM Z FOR Q)
> ORDER BY SUBSTRING(var FROM ABC FOR DEF)
>
> So, tahts with sed, haven't tried awk yet. let you know if I come up
> with something.
>
>
> On Tue, 2010-04-13 at 14:30 +0100, Atif Jung wrote:
> > I've been tasked with writing a script which will automatically update
> > our exisitng INFORMIX code to include POSTGRES compliant equivalent
> > code. My awk skills are pretty basic to say the least, but I've
> > managed to write some of the rules in an awk script, but am having
> > difficulty with the following
> >
> >
> > CHANGE INFORMIX CODE
> >
> > ORDER BY var[x,y];
> >
> > TO POSTGRES CODE
> >
> > ORDER BY SUBSTRING(var FROM x FOR y);
> >
> > my problem is var[x,y] is completely variable. How do I check for that
> > in AWK/SED? Is it even possible?
> >
> > Thanks
> >
> >
> >
>
>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Daniel Hutchison 2010-04-13 15:20:41 Hello, and (hopefully) noob questions
Previous Message glenn 2010-04-13 14:02:24 Re: AWK script