[GRASS-user] Rename multiple sqlite columns at once

Paolo Craveri pcraveri at gmail.com
Tue Nov 4 04:35:16 EST 2008


Hello Nikos

> The command
> v.db.renamecol map=test_rencol column="AREA","area"
>
> does not work. I assume that trying to use 'tr' for example wouldn't
> help (?). Or am I doing something wrong?
>


Try this:


==============
#!/bin/sh
# # # in this example I use nc_spm_07 dataset
# # # I created a sqlite mapset
db.connect driver=sqlite \
	database='$GISDBASE/$LOCATION_NAME/$MAPSET/my_sqlitedb.db'
db.connect -p
g.copy vect=hospitals,myhospitals --overwrite
v.db.connect myhospitals -p
db.columns myhospitals
#
# use awk, function: tolower
# echo "MINNIE" | awk '{print tolower($1)}'
# minnie
# ...and function  substr
#  echo "minnie_tmp"| awk '{print substr($1,1,length($1)-length("_tmp"))}'
# minnie

#skip out duplicate column name error
# (no differences between lower and upper case)
#
#
key_field="cat"
suffix="_tmp"
#THIS MAY TAKE A WHILE...
for field in `db.columns myhospitals`; do
	if [ "$field" != "$key_field" ]; then
		tmpfield=`echo $field | awk '{print tolower($1)}'`
		tmpfield=$tmpfield$suffix
		v.db.renamecol map=myhospitals layer=1 column=$field,$tmpfield
		lower_field=`echo $tmpfield $suffix| awk '{print
substr($1,1,length($1)-length($2))}'`
		v.db.renamecol map=myhospitals layer=1 column=$tmpfield,$lower_field
	fi
done

db.columns myhospitals
=============================



there are same better and more elegant solutions probably...


ciao


Paolo


More information about the grass-user mailing list