bug-coreutils
[Top][All Lists]
Advanced

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

sort -t. -n


From: Charles R. Anderson
Subject: sort -t. -n
Date: Wed, 4 Feb 2004 19:51:04 -0500
User-agent: Mutt/1.4.1i

Program:        sort (coreutils) 4.5.3
Architecture:   i386-redhat-linux
Distribution:   Red Hat Linux 9 - coreutils-4.5.3-19.0.2

I'm not sure if this is a bug, or expected behavior.  sort -t. -n
seems to have a clash between the decimal point '.' and the field
separator '.'.

I have a list of IP addresses I want to sort (these are made up):

123.83.4.172
10.217.225.30
50.50.58.114
32.2.241.89
133.202.54.0
10.225.101.125
73.72.199.134
133.202.185.0
4.129.44.0
10.225.101.125
14.207.60.16
45.157.214.91
217.7.49.84
10.81.90.165
133.202.53.0
56.92.200.247
32.4.109.145
48.163.68.201
45.157.214.90
14.202.80.47
73.68.178.122
123.83.0.0
48.208.8.172
4.129.98.0
4.129.2.0
133.202.52.0

I tried this:

cat list.txt | \
        env LANG=C sort -t. -k1n -k2n -k3n -k4n

But the result is incorrectly sorted:

4.129.2.0
4.129.44.0
4.129.98.0
10.217.225.30
10.225.101.125
10.225.101.125
10.81.90.165
14.202.80.47
14.207.60.16
32.2.241.89
32.4.109.145
45.157.214.90
45.157.214.91
48.163.68.201
48.208.8.172
50.50.58.114
56.92.200.247
73.68.178.122
73.72.199.134
123.83.0.0
123.83.4.172
133.202.185.0
133.202.52.0
133.202.53.0
133.202.54.0
217.7.49.84

If I replace . by , and sort that it works fine:

cat list.txt | \
        sed -e's/\./,/g' | \
        env LANG=C sort -t, -k1n -k2n -k3n -k4n | \
        sed -e's/,/./g'

4.129.2.0
4.129.44.0
4.129.98.0
10.81.90.165
10.217.225.30
10.225.101.125
10.225.101.125
14.202.80.47
14.207.60.16
32.2.241.89
32.4.109.145
45.157.214.90
45.157.214.91
48.163.68.201
48.208.8.172
50.50.58.114
56.92.200.247
73.68.178.122
73.72.199.134
123.83.0.0
123.83.4.172
133.202.52.0
133.202.53.0
133.202.54.0
133.202.185.0
217.7.49.84

Is this a bug, or expected behavior?  Is there any workaround that
doesn't rely on replacing the periods before and after the sort?





reply via email to

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