title: Find if two variables are in the same line
body: <p>I have two lists of IPs. I want to validate that for each pair both exists on the same line in a file: <code>ips_template.txt</code>. If either IP doesn't exists in the file <code>ips_template.txt</code> or they are not a "pair" - print the mismatch. In <code>bash</code> I would just pipe two <code>grep</code>, looking for something with same result.</p>
  
  <pre><code>firstIPs = re.findall(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", firststring)
  secondIPs = re.findall(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", secondstring)
  
  if firstIPs or secondIPs :
      print 'one of the lists didn\'t had IPs.'
      sys.exit(2)
  if len(firstIPs ) != len(secondIPs ):
      print 'IPs len mismatch'
      sys.exit(2)
  
  for old, new in zip(firstIPs , secondIPs ):
  # bash example to search in the file ips_template.txt
  # if [ `cat ips_template.txt | grep old | grep new | wc -l` -gt 0 ]
  #    echo 'match'
  # else
  #    echo ips not matched or missing
  # fi
  </code></pre>
  
  <p><code>ips_template.txt</code> exmaple:</p>
  
  <pre><code>hostname 1.1.1.1 2.2.2.2 hostname_type
  hostname2 1.1.1.1 2.2.2.2 hostname_type2
  </code></pre>
  
  <p><code>firststring</code> and <code>secondstring</code> can be different formats each run and some are unknown. That is why I rip only the IPs from them with the assumptions that the order of the IPs/hosts are same.</p>