sort and trim hostname.