I'd like to extra the top-level domain and the second-level domain from a URL like "https://apple.stackexchange.com/questions/ask"
Example URL with desired result below.
https://apple.stackexchange.com/questions/ask
stackexchange.com
https://www.nytimes.com/2019/07/16/science/5g-cellphones-wireless-cancer.html
nytimes.com
https://nextdoor.com/news_feed/?post=117602&ct=-A17-ghvVOF0tfn9vptW_5a7JOBEyP4w6_hJAZUnMQqN56952&ec=OWKiQRDj9vEHefhwfGYAE0s%3D&lc=1002&is=tpe
nextdoor.com
https://www.amazon.com/gp/product/B007B60SCG/ref=ox_sc_act_title_1?smid=ATVPDKIKX0DER&psc=1
amazon.com
http://www.verizon.net/index.php
verizon.net
I'm ignoring those multi-tier domains. I'd prefer to use Bash on macOS.
There are lots of pages on getting the full domain name:
Extract domain name from URL using bash shell parameter substitution
https://www.cyberciti.biz/faq/get-extract-domain-name-from-url-in-linux-unix-bash/
echo http://example.com/index.php | awk -F[/:] '{print $4}'
I do not need this level of perfection.
.com
domain names? Are you concerned about multi-tier domains, such as.co.uk
?