I am writing a code snippet where I store values from one file to another by grep. So in code below, I am reading from ./stats.txt and storing it two different files on the basis of what I 'grep'. I then want to read these two different files created i.e. out_base.txt and out_base1.txt and do mathematical operation on them. The operation needs floating point handling. I have installed bc and zsh but it still doesn't work:
base1=()
base2=()
grep "system.cpu.branchPred.condPredicted" ./stats.txt >> out_base.txt
file="./out_base.txt"
while IFS=' ' read -r f1 f2 f3
do
base1=($f2)
done <"$file"
grep "system.cpu.branchPred.condIncorrect" ./stats.txt >> out_base1.txt
file="./out_base1.txt"
while IFS=' ' read -r f1 f2 f3
do
base2=($f2)
done <"$file"
((diff=base1[0]-base2[0]))
echo "scale = 2; diff/base2[0]" | bc
I get 0 as my output. I understand I am losing the Floating Point value because bash doesn't handle it, but is there a way to handle this in my script ?