title: Extract all ip addresses with sed and awk from a string
body: <p>It is simple to extract all ip addresses with grep from a string.</p>
  
  <pre><code>string="221.11.165.237xxxx221.11.165.233\n
  219.158.9.97ttttt219.158.19.137"
  echo $string |grep -oP "(\d+\.){3}\d+"
  221.11.165.237
  221.11.165.233
  219.158.9.97
  219.158.19.137
  </code></pre>
  
  <p>The regrex pattern is simple  <code>(\d+\.){3}\d+</code>.<br>
  Do the same job with sed and awk.<br>
  For sed:</p>
  
  <pre><code>echo $string | sed 's/^\(\(\d\+\.\)\{3\}\d\+\)$/\1/g'
  221.11.165.237xxxx221.11.165.233\n 219.158.9.97ttttt219.158.19.137
  </code></pre>
  
  <p>For awk:</p>
  
  <pre><code>echo $string |gawk 'match($0,/(\d+\.){3}\d+/,k){print k}'
  echo $string |awk '/(\d+\.){3}\d+/{print}'
  </code></pre>
  
  <p>How to fix it for sed and gawk(awk)?<br>
  The expect output is the same as grep.</p>
  
  <pre><code>221.11.165.237
  221.11.165.233
  219.158.9.97
  219.158.19.137
  </code></pre>