[GRASS-user] d.slide.show

Ivan Shmakov oneingray at gmail.com
Tue Jul 17 04:07:55 EDT 2007


>>>>> Hamish  <hamish_nospam at yahoo.com> writes:

[...]

 > -       for i in MASK `ls cell/$PREFIX* 2> /dev/null`
 > +#      for i in MASK `ls cell/$PREFIX* 2> /dev/null`
 > +       for i in MASK `ls cell/$PREFIX* | sort -n -k2 -t.`
 >         do
 >                 i=`echo $i | sed 's/cell\///'`
 >                 if [ ! $i = "MASK" ]

[...]

 > The typical solution to this problem is to name the files (maps) as
 > raster.0001, raster.0002, ..., raster.1560.

 > e.g., to rename maps using awk + printf("%04d"):

 > #!/bin/sh
 > for MAP in `g.mlist pattern="raster.*"` ; do
 >   NEW_NAME=`echo "$MAP" | awk -F. '{printf("%s.%04d", $1, $2)}'`
 >   #echo "[$MAP] -> [$NEW_NAME]"
 >   g.rename "$MAP,$NEW_NAME"
 > done

        The sed and gawk are mostly interchangeable for the small tasks.
        What I'd really like to suggest is to use

COMMAND | while read VARIABLE ; do ... done

        loop instead of the currently used

for VARIABLE in `COMMAND` ; do ... done

        one, since the former isn't subject to any command line length
        limits and, besides, makes the code look better (especially if
        one is to have a long pipeline as the COMMAND.)




More information about the grass-user mailing list