#! /bin/sh  
#
# license: Standard BSD2CLAUSE (BSD 2-clause Simplified License),
# Please read from the web.
#
 
# Sort a list of domain names (FQDNs) starting from tld and working left.
# This truly sorts the domain list, lexicographically based on each part 
# of the domain-name, from right to left.


  awk -F"." 's=""; \
   {for(i=NF;i>0;i--) 
     {if (i<NF) s=s "." $i; 
      else 
       s=$i
     }; 
    print s
   }' | sort | sort -u | \

  awk -F"." 's=""; \
   {for(i=NF;i>0;i--)
     {if (i<NF) s=s "." $i;
      else
       s=$i
     };
    print s
   }' 

