[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sort produces incorrect order

From: Nelson, Gregg
Subject: Sort produces incorrect order
Date: Tue, 16 Dec 2003 12:55:01 -0600

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:

The desired sort should produce the following result:

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 appears before

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

Gregg Nelson

reply via email to

[Prev in Thread] Current Thread [Next in Thread]