0

I have below values stored in the respective variables:

s=$(nice grep -i "sf WOW" *`date --date='1 hour ago' +%y%m%d%H`* | grep -i "TRAF:5" | wc -l)
f=$(nice grep -i "sf WOW" *`date --date='1 hour ago' +%y%m%d%H`* | grep -i "TRAF:7" | wc -l)
a=`expr $s + $f`

I need to store the division output in a float variable with an accuracy of 5 digits.

Sachin Aravind
  • 150
  • 1
  • 2
  • 11

1 Answers1

1
echo "scale=5; 355/113" | bc
3.14159
xoid
  • 1,114
  • 1
  • 10
  • 24
  • Hi bro, it didn't work. – Sachin Aravind Oct 30 '19 at 08:49
  • echo "scale=5; x/a" | bc -l Runtime error (func=(main), adr=11): Divide by zero echo $a 110 echo $x 52 – Sachin Aravind Oct 30 '19 at 08:49
  • @SachinAravind `$a` is the bash variable. If you replace xoids example `355/113` with `x/a`, you need to assign the `bc` variables `a` and `x` first: `echo "scale=5; x=$x; a=$a; x/a" | bc -l` - or simply: `echo "scale=5; $x/$a" | bc -l` – Ted Lyngmo Oct 30 '19 at 12:09