title: shell: Extract key value from a string with known key
body: <p>I have a script inside which the following command is run:</p>
  
  <pre class="lang-sh prettyprint-override"><code>OUTPUT=`echo "User-Name=$username,User-Password=$passwd" | radclient $ip auth $key`
  echo $OUTPUT
  </code></pre>
  
  <p>After executing the command I get the following result in <code>OUTPUT</code>.</p>
  
  <pre class="lang-sh prettyprint-override"><code>Received response ID 239, code 2, length = 34
          Reply-Message = "Hello, root"
  </code></pre>
  
  <p>Then I check whether the <code>OUPUT</code> contains <strong>"code"</strong>:</p>
  
  <pre class="lang-sh prettyprint-override"><code>if grep -wq code &lt;&lt;&lt; $OUTPUT; then    
      echo "Success"
      break;
  fi
  </code></pre>
  
  <p>This also works.</p>
  
  <p>Now if my <code>OUTPUT</code> variable contains <strong>code</strong> then I want to extract the code value: <strong>2</strong> (in above case)</p>
  
  <p>How can this be achieved:</p>
  
  <p>So Input: </p>
  
  <pre><code>Received response ID 239, code 2, length = 34
              Reply-Message = "Hello, root"
  </code></pre>
  
  <p>Output: <strong>2</strong></p>