Stripping a path sounds like one operation but the result depends on which of several similar concepts you actually want.
The three levels
https://blog.example.co.uk:8443/post has an origin of https://blog.example.co.uk:8443, a host of blog.example.co.uk, and a registrable domain of example.co.uk. Aggregating by the wrong one produces either fragmented or over-merged results.
Subdomains are a judgement call
blog.example.com and shop.example.com are one organisation and two hosts. For backlink analysis they usually count as one referring domain; for traffic attribution they may need separating. Decide deliberately, because the counts differ substantially.
www is a subdomain
www.example.com and example.com are technically different hosts and almost always the same site. Normalising www away is nearly always correct and is the single most common cause of inflated domain counts.
Use a Public Suffix List library
Reducing to a registrable domain cannot be done by counting dots โ example.co.uk needs three labels while example.com needs two. Only the Public Suffix List knows which.
Try it: Strip URL Path (Keep Domain Only) on SeoWolf's Notepad.