Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Sorting list of domain names by TLD and subdomain

by grinder (Bishop)
on Oct 15, 2003 at 21:15 UTC ( #299555=snippet: print w/replies, xml ) Need Help??

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 ( 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
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://299555]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2016-10-29 01:08 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (387 votes). Check out past polls.