[GRASS-user] Rename multiple sqlite columns at once

Paolo Craveri pcraveri at gmail.com
Thu Nov 6 05:18:35 EST 2008


ciao to all

pay attention to spaces between column name in v.db.renamecol: no
spaces before and after comma.

Command substitution: backticks → $(....)  not substantial
differences; the second form is easier to read and write; it is also
nestable (we are all used to `    ` form, but $() is better (IMHO))

This should work (probably):

================================
db.columns test

key_column="cat"
suffix="_tmp"
for column in `db.columns test`; do
       if [ "$column" != "$key_column" ]; then
               tempcolumn=$(echo $column | awk '{print tolower($1)}')
               tempcolumn=$tempcolumn$suffix
               v.db.renamecol map=test layer=1 column=$column,$tempcolumn
               lower_column=$(echo $tempcolumn $suffix| awk '{print
substr($1,1,length($1)-length($2))}')
               v.db.renamecol map=test layer=1 column=$tempcolumn,$lower_column
       fi
done
db.columns test

===================

ciao

-- 
 Paolo


More information about the grass-user mailing list