title: Bash Script: sed/awk/regex to match an IP address and replace
body: <p>I have a string in a bash script that contains a line of a log entry such as this:</p>
  
  <pre><code>Oct 24 12:37:45 10.224.0.2/10.224.0.2 14671: Oct 24 2012 12:37:44.583 BST: %SEC_LOGIN-4-LOGIN_FAILED: Login failed [user: root] [Source: 10.224.0.58] [localport: 22] [Reason: Login Authentication Failed] at 12:37:44 BST Wed Oct 24 2012
  </code></pre>
  
  <p>To clarify; the first IP listed there "10.224.0.2" was the machine the submitted this log entry, of a failed login attempt. Someone tried to log in, and failed, from the machine at the 2nd IP address in the log entry, "10.224.0.58".</p>
  
  <p>I wish to replace the first occurrence of the IP address "10.224.0.2" with the host name of that machine, as you can see presently is is "IPADDRESS/IPADDRESS" which is useless having the same info twice. So here, I would like to <code>grep</code> (or similar) out the first IP and then pass it to something like the <code>host</code> command to get the reverse host and replace it in the log output.</p>
  
  <p>I would like to repeat this for the 2nd IP "10.224.0.58". I would like to find this IP and also replace it with the host name.</p>
  
  <p>It's not just those two specific IP address though, any IP address. So I want to search for 4 integers between 1 and 3, separated by 3 full stops '.'</p>
  
  <p>Is regex the way forward here, or is that over complicating the issue?</p>
  
  <p>Many thanks.</p>