#!/bin/bash # Reads a list of URLs from stdin, sorts by domain (in reverse label order), protocol, port, auth, and remainder of the URL. python3 -c 'import re, sys'$'\n''for line in sys.stdin:'$'\n'' line = line.strip()'$'\n'' m = re.search(r"^(?P[^/]*)://(?P[^/@]*@)?(?P[^/]*?)(?P:\d+)?(?P(?:/.*)?$)", line)'$'\n'' reversedomain = ".".join(reversed(m["domain"].split(".")))'$'\n'' print(line, reversedomain, m["protocol"], m["port"] or "", m["auth"] or "", m["rest"] or "")' | sort -k2 | cut -d' ' -f1