Hi,
I' using bash and I would like to use "bc" to compute the ratio of of two numbers and assign the ratio to a variable.
The numbers are in a file, e.g.
196.304492
615.348986
Any idea how to do it?
N.B. I cannot change the file to have 196.304492 / 615.348986 as the file is produced by another code.
Maybe I was not clear enough, the numbers are in a file containing these 2 numbers, one in each line.
So my guess would be that I need somehow to create a file or a string from the content of the file...but I can't figure out how.
Thank you,
I would like to try something like Option 1 of pludi
however it seems not to work, maybe because in the file I have a new line character after each number.
The first one should work, since the tr takes care of the newline. If the file is generated with MS-DOS/Windows style line terminators, modify the line to read
This wont work because sed requires the input to already have a newline in it to process the line. The line coming out of the tr command does not contain a new line, so sed will ignore it.
What you can do is this
echo $(sed -e 's#$#\#') 1.0 | bc -l
vgersh99 had a post on this yesterday. If I figure out how to make a nice link I'll put it here.