Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Ever had an alphabetical (or not) list of domain names:

de.yahoo.com mail.example.org www.aol.com www.example.org www.freshmeat.net www.hotdoggie.com.au

... and wished it was sorted by tld (and recursively down the subdomains)?

www.hotdoggie.com.au www.aol.com de.yahoo.com www.freshmeat.net mail.example.org www.example.org

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

In reply to Sorting list of domain names by TLD and subdomain by grinder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 14:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found