[GRASS-dev] Re: [GRASS-SVN] r30420 - grass/trunk/scripts/v.db.renamecol

Markus Neteler neteler at osgeo.org
Mon Mar 3 07:30:33 EST 2008


On Mon, Mar 3, 2008 at 11:53 AM, Maciej Sieczka <tutey at o2.pl> wrote:
>  >> Markus wrote:
>   > Maciek wrote:
>  Hamish pisze:
>
>
>  >>> are you sure that this is portable?
>  >>>
>  >>> if [ "$driver" = "dbf" ] ; then
>  >>> -  NAMELEN=`echo "$newcol" | wc -c | awk '{print $1}'`
>  >>> +  NAMELEN=`echo "$newcol" | wc -c`
>  >>>
>  >>> I darkly remember that some "wc" programs insert odd spaces which
>  >>> would break the script.
>
>  >> I haven't heard of it. Maybe you are right. Let's ask on the dev ML.
>  >> Thoughts, Anybody?
>
>  > 'wc -c filename' will produce output like: '17 filename' (needing awk
>  > or cut) while 'wc -c < filename' or 'cat filename | wc -c' will produce
>  > output like: '17'. Maybe that is the dark memory?
>
>  That could explain the " awk '{print $1}' ". Markus?

Possibly yes. As said: darkly remembered...

>  > For curiosity, what's so bad about using awk?
>
>  Invoking the allmighty awk just to do what cut is designed for seems an
>  overkill to me. Awk is not needed for anything in v.db.renamecol. Cut
>  suffices. Keep it simple, the UNIX way of specialized tools and stuff.
>
>  > speed?
>
>  Actually cut itself seems slightly slower than awk for this sort of task:
>
>  $ x=0; time while [ $x -lt 1000 ]; do echo "raz dwa" | cut -d" " -f2 >
>  /dev/null ; x=`expr $x + 1`; done
>
>  on my machine is about 7% slower than
>
>  $ x=0; time while [ $x -lt 1000 ]; do echo "raz dwa" | awk '{print $2}'
>   > /dev/null ; x=`expr $x + 1`; done
>
>
>  On the other hand, after replacing all awk with cut in the script,
>  removing the test for awk's presence:
>
>
>  #### check if we have awk
>  if [ ! -x "`which awk`" ] ; then
>      g.message -e "awk required, please install awk or gawk first"
>      exit 1
>  fi
>
>  resulted in a speed boost. In the end, v.db.renamcol without awk is as
>  fast as it was with awk.

At this point I don't see why do this effort.
There is the risk to introduce new bugs (as seen here) and
there is no point in saving 7% of 10 nanoseconds. Since
awk is needed in GRASS it can also be used here.

Why not using efforts for more important things?

Markus


More information about the grass-dev mailing list