[GRASS5] r.to.pg: awk question

Markus Neteler neteler at geog.uni-hannover.de
Wed Jul 26 06:32:38 EDT 2000


On Wed, Jul 26, 2000 at 10:58:40AM +0200, Bernhard Reiter wrote:
> On Tue, Jul 25, 2000 at 09:12:00PM +0200, Andreas Lange wrote:
> > the awk prog enclosed in '' is not evaluated by the shell so that there
> > is no substitution of variable names. This would be bad as all other
> > strings would be evaluated by the shell.
> 
> Correct.
> 
> > You could echo the program to a temporary file and use awk -f tmpfile.
> > Or you can supply the string on the awk command line and use "'$1'" to
> > get it in the awk skript.
> 
> Both too complicated.
> gawk (which is the standard awk now, derived from the POSIX version of
> the new awk) has the ENVIRON field. So you can access environment
> variables from within awk. Try     awk  ' { print ENVIRON["PATH"] } ' 
> (and press return, because awk still reads lines. :) )
> 
> The second possibility is to use the "-v" flags to bring variables in.
> 
> 
> > > TABLENAME="somestring"
> > > #get the raster values and write out SQL:
> > > r.stats -1 nv='-9999' in=$1 | awk 'BEGIN{}
> > >   NR == 1{}
> > >          {printf "INSERT INTO %s VALUES ( %.5f);\n", ENVIRON["TABLENAME"] , $1  >> "/tmp/pgimport.sql"}
> > > END{}'

Unfortunately my "awk" dislikes  the ENVIRON.
Any other ideas? I would be glad to get this into GRASS 5b8.

I try         -v var=val              --assign=var=val
now.

Markus

---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list