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
there is so little info on how you get those urls...please show more info next time. are there parameters in the url etc etc... Meanwhile, just simple string manipulation for your sample url
eg
$ s="http://example.com/index.php"
$ echo ${s/%/*} #get rid of last "/" onwards
http://example.com
$ s=${s/%\//}
$ echo ${s/#http:\/\//} # get rid of http://
example.com
other ways, using sed(GNU)
$ echo $s | sed 's/http:\/\///;s|\/.*||'
example.com
use awk
$ echo $s| awk '{gsub("http://|/.*","")}1'
example.com