title: Floating-point arithmetic in UNIX shell script
body: <p>How to do arithmetic with floating point numbers such as <strong>1.503923</strong> in a shell script? The floating point numbers are pulled from a file as a string. The format of the file is as follows:</p>
  
  <pre><code>1.5493482,3.49384,33.284732,23.043852,2.2384...
  3.384,3.282342,23.043852,2.23284,8.39283...
  .
  .
  .
  </code></pre>
  
  <p>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.</p>
  
  <pre><code># 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
  </code></pre>
  
  <p>Output I keep getting:</p>
  
  <pre class="lang-none prettyprint-override"><code>expr: non-numeric argument
  command not found
  </code></pre>