Replace 'cut -c' calls by ksh internals

From: Jean-Marc Monnez (monnez.jean-marc@AGORA.MSA.FR)
Date: Fri Jul 12 2002 - 05:10:50 EDT


Hello all,

Some people have developped apps in ksh and they are much called for our
production. These apps stress a lot the system, especially with external
ksh calls (cut, grep, shell redirections...) : lots of fork/exec, lots
of processes waiting for CPU.
I began optimizing the scripts by replacing lots of the external calls
by shell internals. This way the system is much less stressed by fork
calls, and the script dynamic priority is more significant of the system
CPU it really got to do its job.

One simple example, replace :
var1=$(echo $var | cut -f1 -d';')
with
var1=${var%%;*}
avoids 3 fork/exec.

I have a problem with replacing the 'cut -c' calls with shell internals,
and there are lots of them, like :
var1=$(echo $var | cut -c10-15)

My today's substitution for this seems quite heavy :
var1=$var
carstart=10
carlength=6
i=1
while (( $i < $carstart ))
do
echo $i
    var1=${var1#?}
    i=$(($i + 1))
done
while (( ${#var1} > $carlength ))
do
    var1=${var1%?}
done

Anyone have a cleverer mean of doing the same with ksh internals ?

-- JMM

PS : i need use of standard ksh 88 on AIX, ksh 93 is not available for
me.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:03 EDT