title: How do I extract a certain number from an Expect buffer string?
body: <p>I would like to get the total memory of a host by using an Expect script. Thanks to the answers I received in <a href="https://stackoverflow.com/questions/10277503/get-total-memory-of-a-host-with-linux-expect">Get Total Memory of a host with LINUX/EXPECT</a> I am now closer to the final solution. (Thanks to <a href="https://stackoverflow.com/users/7552/glenn-jackman">glenn jackman</a> and <a href="https://stackoverflow.com/users/180736/sorpigal">Sorpigal</a>).</p>
  
  <p>After connecting to the host, I execute the following line:</p>
  
  <pre><code>send "cat /proc/meminfo | grep MemTotal | awk '{print \$2}'\r"
  </code></pre>
  
  <p>It returns the value I want, but when I get the value contained in <code>$expect_out(buffer)</code>, it contains much more info than I need, including the send sentences and the previous and posterior command prompt flags. I exactly get the following, using <code>exp_internal 1</code>:</p>
  
  <pre><code>expect: set expect_out(buffer) "17# cat /proc/meminfo | grep MemTotal | awk '{print $2}'\r\n34150400\r\nCBA"
  </code></pre>
  
  <p>I want to extract just the number near the end, <code>34150400</code>. Any hint or idea?</p>