the file is like this
ATOM 1 HO5' C 1 3.429 -7.861 3.641 1.00 0.00 H
ATOM 2 O5' C 1 4.232 -7.360 3.480 1.00 0.00 O
ATOM 3 C5' C 1 5.480 -8.064 3.350 1.00 0.00 C
ATOM 4 H5' C 1 5.429 -8.766 2.518 1.00 0.00 H
I want to store these into 2D array, do some calculation with values and retrieve later I declared arrays as follows,
I split the file as follows,
readarray row < sample.pdb
IFS=' \t\r\n' read -a cell <<< "$row"
for (( r = 0; r <= ${#row[@]}; r++ )) # row
do
for (( c = 0 ; c <= ${#cell[@]}; c++ )) #cells
do
echo ${cell[$c]}
declare -A matrix[$r,$c]="${cell[$c]}"
done
done
and trying to retrieve as follows
for ((j=0; j<=${#row[@]}; j++))
do
for ((i=0; i<=${#cell[@]}; i++))
do
echo ${matrix[$j,$i]}
done
done
Expected output
ATOM
1
HO5'
C
1
3.429
-7.861
3.641
1.00
0.00
H
ATOM
2
O5'
C
1
4.232
-7.360
3.480
1.00
0.00
O
AND THE OTHER LINE
but the output is (first line repeat again and again)
ATOM 1 HO5' A 1 3.429 -7.861 3.641 1.00 0.00 H
ATOM 1 HO5' A 1 3.429 -7.861 3.641 1.00 0.00 H
I would like to know the appropriate 2D dimensional splitting.