Ever had an alphabetical (or not) list of domain names:
... and wished it was sorted by tld (and recursively down the subdomains)?
From the shell, it's a snap: perl -ple'$_=join".",reverse split/\./' reverse the domain components (mail.example.org becomes org.example.mail). This can then be piped to another filter (e.g. sort) and then the same filter can be run again to undo the reversal.
It's even easier if the command is wrapped up in an alias. (And yes, I know about "Useless use of cat(1)". I'm using it here to show the symmetry of the munging/demunging).
cat foo | perl -ple'$_=join".",reverse split/\./' | sort | \ perl -ple'$_=join".",reverse split/\./' # or alias tldmunge='perl -ple'"'"'$_=join".",reverse split/\./'"'" cat foo | tldmunge | sort | tldmunge
|Replies are listed 'Best First'.|
Re: Sorting list of domain names by TLD and subdomain
by Anonymous Monk on Sep 14, 2018 at 16:50 UTC