title: How to extract a substring matching a pattern from a Unix shell variable
body: <p>I'm relatively new to Unix shell scripting. Here's my problem. I've used this script...</p>
  
  <pre><code>isql -S$server -D$database -U$userID -P$password &lt;&lt; EOF &gt; $test
  exec MY_STORED_PROC
  go
  EOF
  
  echo $test
  </code></pre>
  
  <p>To generate this result...</p>
  
  <pre><code>Msg 257, Level 16, State 1:
  Server 'MY_SERVER', Procedure 'MY_STORED_PROC':
  Implicit conversion from datatype 'VARCHAR' to 'NUMERIC' is not allowed.  Use
  the CONVERT function to run this query.
  (1 row affected)
  (return status = 257)
  </code></pre>
  
  <p>Instead of echoing the isql output, I would like to extract the "257" and stick it in another variable so I can return 257 from the script. I'm thinking some kind of sed or grep command will do this, but I don't really know where to start.</p>
  
  <p>Any suggestions?</p>