Friday, December 18, 2009

HOWTO: sort /etc/hosts by IP numerically

sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /etc/hosts

1 comment:

Eric Sherrill said...

and then find dupes:

sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 /etc/hosts | cut -f1 -d " "| cut -c1-13 | uniq -d

YMMV on the -c1-13 part... could be up to 16 chars long e.g. 255.255.255.255 after all.