[GRASSLIST:4612] Re: String splitting in BASH...

Using an index certainly speeds this up, but things are still kind of
slow -
80,000 records takes an hour or two.

A further speed up was acheived by using:
    echo "update allpoly_att set age = $AGE, cover= $COVER where avicat
= $MYCAT" | db.execute

instead of two separate calls for both "age" and "cover".

What I would like to do is:

RET = echo "select age, cover from play_att where link_key = $MYCAT" |
db.select -c`

where RET will look something like "100|1002". I then use BASH to
string split RET and assign to AGE and COVER (both integers).
This would elliminate one database query and would speed things up
further.

But I can't figure out how to do this string-splitting in BASH!!

Cheers!
Craig

On Mon, 2004-10-11 at 02:52, Radim Blazek wrote:

On Thursday 07 October 2004 00:03, Craig Aumann wrote:
> The code is very simple:
>
>
> for MYCAT in `echo "select distinct avicat from

allpoly_att"|db.select

> -c`; do
> echo $MYCAT
> AGE=`echo "select age from play_att where link_key = $MYCAT" |
> db.select -c`
> COVER=`echo "select cover from play_att where link_key = $MYCAT"

|

> db.select -c`
>
> echo "update allpoly_att set age = $AGE where avicat = $MYCAT" |
> db.execute
> echo "update allpoly_att set cover = $COVER where avicat =

$MYCAT" |

> db.execute
> done
>
>
> Right now, it is doing about 2 updates per second - which is too

slow!

> Is the slowness caused by piping it through db.execute?
>
> Other suggestions for speeding this up?

Postgres + index for link_key and avicat.

Radim

I'm not shure I understand what you want but I'd give awk a try.

You could do something like awk {print $1} to get the first column.
You just have to set the delimiter. I think it's -F "|" but not shure.

cheers
Daniel

On Fri, 22 Oct 2004 09:21:31 -0600, Craig Aumann <caumann@ualberta.ca> wrote:

Using an index certainly speeds this up, but things are still kind of
slow -
80,000 records takes an hour or two.

A further speed up was acheived by using:
    echo "update allpoly_att set age = $AGE, cover= $COVER where avicat
= $MYCAT" | db.execute

instead of two separate calls for both "age" and "cover".

What I would like to do is:

RET = echo "select age, cover from play_att where link_key = $MYCAT" |
db.select -c`

where RET will look something like "100|1002". I then use BASH to
string split RET and assign to AGE and COVER (both integers).
This would elliminate one database query and would speed things up
further.

But I can't figure out how to do this string-splitting in BASH!!

Cheers!
Craig

On Mon, 2004-10-11 at 02:52, Radim Blazek wrote:
> On Thursday 07 October 2004 00:03, Craig Aumann wrote:
> > The code is very simple:
> >
> >
> > for MYCAT in `echo "select distinct avicat from
allpoly_att"|db.select
> > -c`; do
> > echo $MYCAT
> > AGE=`echo "select age from play_att where link_key = $MYCAT" |
> > db.select -c`
> > COVER=`echo "select cover from play_att where link_key = $MYCAT"
|
> > db.select -c`
> >
> > echo "update allpoly_att set age = $AGE where avicat = $MYCAT" |
> > db.execute
> > echo "update allpoly_att set cover = $COVER where avicat =
$MYCAT" |
> > db.execute
> > done
> >
> >
> > Right now, it is doing about 2 updates per second - which is too
slow!
> > Is the slowness caused by piping it through db.execute?
> >
> > Other suggestions for speeding this up?
>
> Postgres + index for link_key and avicat.
>
> Radim
>

Craig Aumann wrote:

But I can't figure out how to do this string-splitting in BASH!!

Would subsection "Parameter Expansion" in bash(1) be of any use?

Matej

--
Matej Cepl, http://www.ceplovi.cz/matej
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC
138 Highland Ave. #10, Somerville, Ma 02143, (617) 623-1488

See, when the GOVERNMENT spends money, it creates jobs; whereas
when the money is left in the hands of TAXPAYERS, God only knows
what they do with it. Bake it into pies, probably. Anything to
avoid creating jobs.
    -- Dave Barry

What I would like to do is:

RET = echo "select age, cover from play_att where link_key = $MYCAT" |
db.select -c`

where RET will look something like "100|1002". I then use BASH to
string split RET and assign to AGE and COVER (both integers).
This would elliminate one database query and would speed things up
further.

But I can't figure out how to do this string-splitting in BASH!!

awk will certainly work. many ways to solve a problem.

here's another, maybe more simple:

AGE=`echo "$RET" | cut -f1 -d'|'`
COVER=`echo "$RET" | cut -f2 -d'|'`

Hamish