[GRASS-user] Getting rows,cols of a region in a script

Nikos:

> I need the number of rows and columns to use with v.mkgrid. Currently I
> use the following, rather long and complex command:
> g.region -g | grep o | cut -d"=" -f2 | tr "\n" "," | cut -d"," -f1,2

Martin wrote:

in Python

ret = grass.read_command('g.region', flags = 'g')
reg = grass.parse_key_val(ret)
print '%d,%d' % (int(reg['rows']), int(reg['cols']))

in the shell

eval `g.region -g`
echo $rows,$cols

:slight_smile:
Hamish