Text on a line after the IP address is carried along unchanged. Thus, sorthosts will sort your /etc/hosts file, and the hostnames and aliases will remain unaltered.
Lines without an initial number are considered "separators"; they are output unchanged, and a sequence of IP addresses between such separators is sorted as one sequence.
127.0.0.1 localhost 16.126.32.251 buffie.mko.dec.com buffie 16.126.64.250 mkons1.mko.dec.com mkons1 # BIND server 16.126.128.148 apache.mko.dec.com apache 16.46.48.214 mpeg2.mko.dec.com mpeg2 16.126.224.58 tlase1.mko.dec.com tlase1 16.126.64.250 mkons1.mko.dec.com mkons1 # BIND server 16.23.14.47 some.where.dec.com swh # FDDIs in lab: 10.0.48.214 mpeg2-fta0 mpeg2-10-0 mpeg2-tlase1 10.0.224.58 tlase1-fta0 tlase1-10-0 tlase1-mpeg2 10.1.64.156 imfine-fta1 imfine-10-1 imfine-tlase1 10.1.224.58 tlase1-fta1 tlase1-10-1 tlase1-imfineThe command:
sorthostswill produce the file sortedhosts with contents:sortedhosts
127.0.0.1 localhost 16.23.14.47 some.where.dec.com swh 16.46.48.214 mpeg2.mko.dec.com mpeg2 16.126.32.251 buffie.mko.dec.com buffie 16.126.64.250 mkobnd.mko.dec.com mkobnd # BIND server 16.126.64.250 mkons1.mko.dec.com mkons1 # BIND server 16.126.128.148 apache.mko.dec.com apache 16.126.224.58 tlase1.mko.dec.com tlase1 # FDDIs in lab: 10.0.48.214 mpeg2-fta0 mpeg2-10-0 mpeg2-tlase1 10.0.224.58 tlase1-fta0 tlase1-10-0 tlase1-mpeg2 10.1.64.156 imfine-fta1 imfine-10-1 imfine-tlase1 10.1.224.58 tlase1-fta1 tlase1-10-1 tlase1-imfineYou might want to pipe sorthosts's output throutgh uniq(1) to remove duplicate entries. SEE ALSO