title: read value from txt file in javascript
body: <p>I have a simple html file in which there's javascript code referring to google charts. </p>
  
  <p>The code I use is this (I'll show the important part):</p>
  
  <pre><code>function drawChart(){
      var data = google.visualization
                       .arrayToDataTable([ ['Label', 'Value'],['Temp', 22.75],]);
  
      // etc...
  }
  </code></pre>
  
  <p>I use a bash command (sed) to replace that 22.75 value with a new one from the last line of a .txt file. However, this throws some errors which I haven't been able to neither correct nor ever identify.</p>
  
  <p>So is there any javascript code that takes that file, extracts the last value and simply displays it on the right place of the code?</p>
  
  <p>UPDATE:</p>
  
  <p>Sorry for the lack of info in this question, I really appreciate all the people that took the time on reading my question. I'll try to fill with more information in the next minutes.</p>
  
  <p>I am able to extract the last line of the .txt file, extract the value on the right part of the '-' symbol and store it in a variable. Then that value is taken to update the html file with a sed command. The error comes when the value is updated but with no value. I guess that happends due to a failed record of temperature in the txt file, then the extracted value is a null. Finally is the html fiel with javascrit code happens to be like this:</p>
  
  <p>(...)['Temp'<strong>, ],</strong>]);</p>
  
  <p>Then the updater can't update the value since due to the way that sed command is written I guess there's no way that it can detect a no-number-value in there. So the html remains without a value all the time.</p>
  
  <p>TXT File structure:</p>
  
  <p>(...)
  <br/>
  20:25:03-23.312<br/>
  20:26:02-23.312<br/>
  20:27:03-23.375<br/>
  20:28:03-23.375<br/>
  20:29:02-23.375<br/>
  20:30:02-23.312<br/></p>
  
  <p>Bash script:</p>
  
  <pre><code># (...code...)
  lastRecord=`cat /home/pi/scripts/temp_control/logs/"$today".log | awk 'END{print}'`
  
  function rightNow {
    lastTemp=`echo $lastRecord | cut -d'-' -f2`
  
    timeOfTemp=`echo $lastRecord | cut -d'-' -f1` # Not used yet
  
    #Command used to update
    sed -i "s/['Temp', [0-9]\{1,2\}.[0-9]\{1,3\}]/$lastTemp]/" /var/www/rightnow.html
  }
  
  rightNow
  </code></pre>