I'm trying to find derive SCALEFACTOR which is basically 10000/(sum of 4th column in a file). How do I get a decimal from the output? Appreciate any help in advance.
#!/bin/bash
FILES=/path/to/files/*;
for f in ${FILES}
do
echo $f
COLTOTAL="$(awk '{sum += $4} END {print sum}' $f)"
echo "total: ${COLTOTAL}"
# SCALEFACTOR=`expr 10^5 / $COLTOTAL`
B=10000
SCALEFACTOR=$((B / ${COLTOTAL}))
SCALINGFACTOR=$(echo "100000 / $COLTOTAL" | bc -l
# echo "scale=5; ${SCALEFACTOR}" | bc
echo ${SCALEFACTOR}
awk '{print($1"\t"$2"\t"$3"\t"$4 * ${SCALINGFACTOR})}' $f > $f"_normalized.txt"
done
Aucun commentaire:
Enregistrer un commentaire