CUFP
grinder
snippet
<div class="Description"><p>Ever had an alphabetical (or not) list of domain names:</p>
<code>de.yahoo.com
mail.example.org
www.aol.com
www.example.org
www.freshmeat.net
www.hotdoggie.com.au</code>
<p>... and wished it was sorted by tld (and recursively down the subdomains)?</p>
<code>www.hotdoggie.com.au
www.aol.com
de.yahoo.com
www.freshmeat.net
mail.example.org
www.example.org</code>
<p>From the shell, it's a snap: <code>perl -ple'$_=join".",reverse split/\./'</code> reverse the domain components (<code>mail.example.org</code> becomes <code>org.example.mail</code>). This can then be piped to another filter (<i>e.g.</i> <tt>sort</tt>) and then the same filter can be run again to undo the reversal.</p>
<p>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).</p></div>
<CODE>
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
</CODE>