Help! I have an array with unknown # of subscripts. When certain condition is met, I need to print out the various elements and repeat by adding 6. So output should look something like:
print "${A[1]} ${A[2]} ${A[3]}"
print "${A[7]} ${A[8]} ${A[9]}"
print "${A[13]} ${A[14]} ${A[15]}"
etc, and keep going until EOF.
I only have unix, preferrably ksh, no perl available. Any suggestions are greatly appreciated!
leslie02
Leslie,
Is this what you want:
typeset -i mInd1=1
typeset -i mInd2
typeset -i mInd3
while [ ${mInd1} -le 30 ]
do
mInd2=${mInd1}+1
mInd3=${mInd1}+2
print ${A[${mInd1}]} ${A[${mInd2}]} ${A[${mInd3}]}
mInd1=${mInd1}+6
done
This enumerates an array by three's:
while (( i < ${#A[*]} ))
do
echo "${A} ${A[i+1]} ${A[i+2]}
let i=i+3
done
If you are going to "refill" the array
unset A
will clear all of the entries and set length to zero