[GRASS-user] generating a TXT file with "for..done" looping

Hamish hamish_b at yahoo.com
Wed Nov 12 21:04:14 EST 2008


Milton Cezar Ribeiro wrote:

> I built the short code below and if I run if I run it under "bash" I can
> generate a list of command that after I can copy and past, and
> run under the same "bash" session. If I try remove the "echo"
> I get errors. As the list of HEXID is so long (about 3.000)
> I need to run the code below in parts, and do a lot of copy-and-past
> to reach up the desidere result.
> 
> My question is if I can generate and text file to run all HEXIDs on one
> session. I tryed change "echo.." by "cat ...
> >
> c:/grass/scripts/myscript.txt"
> but the file get some stranger simbols and I am not sure if
> grass will understand it.
> 
> I run native wingrass 6.3.0, not under MSYS or linux.
....
> for HX in `v.db.select map=hex001000ha_clip column=HEXID
> where="HEXID<=100"`; do
> echo v.extract --o input=hex001000ha_clip
> output=vec_hex_temp where="\"`echo
> HEXID=$HX`"\"
> echo g.region vect=vec_hex_temp res=2.5
> echo v.to.rast input=vec_hex_temp output=rast_hex_temp
> use=cat
> echo r.mapcalc
> "\"rast_hex_temp_1=if(rast_hex_temp>0,1,null())"\"
> echo r.mapcalc
> "\"rast_hex_temp_1_uso=Floresta_Vale1Vale2_2pt5m_MATA_fundo3*rast_hex_temp_1"\"
> echo r.stats -a input=rast_hex_temp_1_uso
> output=D:/Usuarios/qtdhex1000_hexid`echo $HX`.txt
> echo g.remove -f vect=vec_hex_temp
> echo g.remove -f
> rast=rast_hex_temp,rast_hex_temp_1,rast_hex_temp_1_uso
> echo g.region -d
> echo #
> done

[sorry about the line wraps, yahoo's fault]


disclaimer: I don't know much about wingrass.


suggestion 1:
 echo "text" >> c:/grass/scripts/myscript.txt"

">>" appends to the file, ">" overwrites the file each time


suggestion 2: 
perhaps put the ">" after the done, not after each echo? Perhaps that
needs the entire for...done loop inside parentheses:
  ( for ... done ) > outfile.txt
?


Hamish



      



More information about the grass-user mailing list