I am trying to sort a list of IP addresses into numerical order. 
By "numerical order" I mean that each octet is sorted in ascending order and
that all four octets are used as keys from left to right. I also wish to
delete duplicates.

Suppose the list contains the following lines:
192.168.123.5
192.168.21.4
192.168.12.6
192.168.21.4

The desired sort should produce the following result:
192.168.12.6
192.168.21.4
192.168.123.5

Several commands I've tried in an attempt to achieve this result are:
        sort -t\. -nuo output-file input-file
        sort -t\. -k1 -k2 -k3 -k4 -nuo output-file input-file
        sort -t\. -k1n -k2n -k3n -k4n -uo output-file input-file

Each of the above examples produces an incorrect order in which address
192.168.123.5 appears before 192.168.21.4.

I believe the problem occurs because sort is not aligning the assumed
decimal point in each key field even though a numerical (-n) sort is
specified.

Gregg Nelson


_______________________________________________
Bug-textutils mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-textutils

Reply via email to