title: How to grep multiple strings on same line in Ruby
body: <p>How can I modify my <code>if</code> statement to grep for multiple strings on the same line?</p>
  
  <pre><code>string = "1.1.1.1 example.com"
  if File.readlines("/etc/hosts").grep(/#{string}/).any?
      exit
  else
      File.open("/etc/hosts", "w") { |file| file.write(host_file)}
  end
  </code></pre>
  
  <p>This is how it works in bash:</p>
  
  <pre><code>if grep -q "1.1.1.1 example.com";
    then
        exit
  else
      echo "1.1.1.1 example.com" &gt;&gt; /etc/hosts
  fi
  </code></pre>