mardi 24 février 2015

How do you derive a decimal from a math operation involving a variable?


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}))
# echo "scale=5; ${SCALEFACTOR}" | bc
echo ${SCALEFACTOR} | bc -l
done


Aucun commentaire:

Enregistrer un commentaire