I'm trying to print an associative vector with decimals on the screen but I can not find a way to do it:
#!/bin/bash
cantidades="cantidades.csv"
line=20
declare -A sumaCantidad
declade -A media
declare -A numeroCantidades
for i in 'seq 2 $line'
do
NOMBRE='cat $cantidades | sort -n -k2 -t"," | head -n$i | tail -n1 | cut -d ',' -f4'
CANTID='cat $cantidades | sort -n -k2 -t"," | head -n$i | tail -n1 | cut -d ',' -f5'
sumaCantidad[$NOMBRE]=$((sumaCantidad[$NOMBRE]+CANTID))
numeroCantidades[$NOMBRE]=$((numeroCantidades[$NOMBRE]+1))
done
for i in 'seq 2 $line'
do
NOMBRE='cat $cantidades | sort -n -k2 -t"," | head -n$i | tail -n1 | cut -d ',' -f4'
media[$NOMBRE]={sumaCantidades[$NOMBRE]}/${numeroCantidades[$NOMBRE]}
echo "$media[$NOMBRE]}"
done
What happens is that when printing the media only prints the whole number, without decimals, and I want you to do the operation with decimals. How could I do it?
The file looks like this
[...],[...],[...],NOMBRE,CANTIDAD
0,0,0,Juan,4
0,0,0,Juan, 7
0,0,0,Jose,10
0,0,0,Maria,4
0,0,0,Maria,6
etc