CASE 1
Given 'http://a.b.c.d/dir1/dir2/x.html', what we want is
http://a.b.c.d/dir1/dir2/
That is, get rid of the last part:
Script and Comments
Script1 [sed]
[ 1] s|[^/]*$||
CASE 2
Given 'http://a.b.c.d/dir1/dir2/x.html', what we want is
http://a.b.c.d/
That is, keep only the host+domain part.
Script and Comments
Script1 [perl]
[ 1] s|^((.*?/){3}).*|$1|
Script2 [sed]
[ 1] s|^\(\([^/]*/\)\{3\}\).*|\1|