You statement of
echo "$a, \c" >>sample.txt
...would actually generate a comma&space separated file. I presume you mean:-
echo "$a,\c" >>sample.txt
followed by a plain echo at the end of the process.
Anyway, this indirect phrase I used.
If you are using ksh, then the arrays are limited to being one dimensional, i.e. you can only specify one ordinate. If you could specify two, then this would be easier. The logic would work that if you had arrays A and gave them ordinates x & y in a reference that identified a single value as A[x,y] then we could load the array by using a pair of loops like this (not runnable code)
x=1
y=1
until [ $x -ge 15 ]
do
until [ $y -gt 15 ]
do
{read value into A[$x,$y]}
{increment y}
done
{increment x}
done
Then you could write the data out again looping the other way around, such as:-
x=1
y=1
until [ $y -ge 15 ]
do
until [ $x -gt 15 ]
do
{write value from A[$x,$y]}
{increment x}
done
{increment y}
done
If your shell does not support two diminsional arrays (such as ksh need to check ksh93) we may have to be more inventive. The indirect variable would be a way of trying to use a variable as a variable name, so you make one of the ordinates part of the variable, so if the 2D array is A you would actually define a set of 1D arrays, A1, A2, A3, A4, ...... for as many values of x as you would have. You could then refer to $A3[5] as being array cell 3,5 as it were. The trick is how to get the array name as a variable. It could get messy.
It depends how one would write something like:-
echo "${A$x[$y]}"
.... which I'm not sure how to code up.
I'm not sure if this helps, but it may bring further suggestions - and I may learn something too!
Robin
Liverpool/Blackburn
UK