How to extract domain name from url?
$ URI="http://user:pw@example.com:80/"$ echo $URI | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/'example.com
basename "http://example.com"
Now of course, this won't work with a URI like this: http://www.example.com/index.html
but you could do the following:
basename $(dirname "http://www.example.com/index.html")
Or for more complex URIs:
echo "http://www.example.com/somedir/someotherdir/index.html" | cut -d'/' -f3
-d means "delimiter" and -f means "field"; in the above example, the third field delimited by the forward slash '/' is www.example.com.