How do I extract the domain name from a url using bash? like: http://example.com/ to example.com must work for any tld, not just .com
The following will output "example.com":
URI="http://user@example.com/foo/bar/baz/?lala=foo" ruby -ruri -e "p URI.parse('$URI').host"
For more info on what you can do with Ruby's URI class you'd have to consult the docs.