KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How to do arithmetic with floating point numbers such as 1.503923 in a shell script? The floating point numbers are pulled from a file as a string. The format of the file is as follows: 1.5493482,3.49384,33.284732,23.043852,2.2384... 3.384,3.282342,23.043852,2.23284,8.39283... . . . Here is some simplified sample code I need to get working. Everything works fine up to the arithmetic. I pull a line from the file, then pull multiple values from that line. I think this would cut down on search processing time as these files are huge. # set vars, loops etc. while [ $line_no -gt 0 ] do line_string=`sed -n $line_no'p' $file_path` # Pull Line (str) from a file string1=${line_string:9:6} # Pull value from the Line string2=${line_string:16:6} string3=... . . . calc1= `expr $string2 - $string7` |bc -l # I tried these and various calc2= ` "$string3" * "$string2" ` |bc -l # other combinations calc3= `expr $string2 - $string1` calc4= "$string2 + $string8" |bc . . . generic_function_call # Use the variables in functions line_no=`expr $line_no - 1` # Counter-- done Output I keep getting: expr: non-numeric argument command not found
Tags (comma-separated)
Save Edits
Cancel