[GRASS-user] Rename multiple sqlite columns at once

Moritz Lennert mlennert at club.worldonline.be
Thu Nov 6 13:59:19 EST 2008


On 06/11/08 17:37, Nikos Alexandris wrote:
> On Thu, 2008-11-06 at 11:18 +0100, Paolo Craveri wrote:
>> 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
> 
> Ciao Paolo & Moritz!
> Thank you for your assistance.
> 
> 
> @Moritz: I tried it but still not clean.
> # cat caps_2_lower_moritzx.sh -n
>      1	#!/bin/sh -x
>      2	
>      3	key_column="cat"
>      4	suffix="\_tmp"
>      5	for column in `db.columns test`; do
>      6	        if [ "$column" != "$key_column" ]; then
>      7	                tempcolumn=`echo $column | awk '{print
> tolower($1)}'`
>      8	                tempcolumn="$tempcolumn""\_tmp"
>      9			echo $tempcolumn
>     10	                v.db.renamecol map=befliegung_copy column=
> $column,$tempcolumn
>     11			lower_column=`echo $tempcolumn $suffix | awk '{print
>     12	substr($1,1,length($1)-length($2))}'`

[...]

> 
> # output
> block_id\_tmp

I think this is because of the quotes:

tempcolumn="$tempcolumn""\_tmp"

But actually, trying out your entire original script, I don't see where 
the problem is. The attached version seems to work perfectly for me 
(just slightly simplified from your original version):

What exactly did not work when you tried this ?

Moritz
-------------- next part --------------
A non-text attachment was scrubbed...
Name: change_case.sh
Type: application/x-shellscript
Size: 412 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/grass-user/attachments/20081106/52efa774/change_case.bin


More information about the grass-user mailing list