[GRASS5] r.to.pg: awk question

Bernhard Reiter bernhard at intevation.de
Wed Jul 26 04:58:40 EDT 2000


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{}'

-- 
Professional Service around Free Software                (intevation.net)  
The FreeGIS Project				            (freegis.org)
Association for a Free Informational Infrastructure            (ffii.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 236 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-dev/attachments/20000726/fa66b30f/attachment.bin


More information about the grass-dev mailing list