You are not logged in.

#1 2015-07-25 21:08:39

Sarvadamana
Member
Registered: 2012-06-08
Posts: 14

How do I get my computer to realize 2 comes before 10?

I was wondering if there is a program out there, or some text file I have to edit that could make it so that when my computer is sorting (regardless of what program I am using), that it will recognize that 2 comes before 10, 100, 132123, etc... It's very frustrating to have to change all my numbers to "0000001" in order for the computer to sort them correctly. A big thanks to anyone that knows how to do this!

Offline

#2 2015-07-25 21:10:23

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: How do I get my computer to realize 2 comes before 10?

Recognising them in what?

Not a GNU/Linux discussion, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-07-25 21:38:08

nachosduyo
Member
From: Slovenia
Registered: 2015-03-10
Posts: 5

Re: How do I get my computer to realize 2 comes before 10?

The easiest way to sort numbers would probably be to just use "sort". It has a flag -n, which will make it sort according to the numerical values instead of alphabetically.

Example of processing a file nums.txt:

cat nums.txt
10
100
132123
2

cat nums.txt | sort
10
100
132123
2

cat nums.txt | sort -n
2
10
100
132123

This is what you wanted, correct?

Offline

#4 2015-07-25 22:29:46

snakeroot
Member
Registered: 2012-10-06
Posts: 164

Re: How do I get my computer to realize 2 comes before 10?

Or, for listing directories"

ls -v

other random solutions to related problems here.

Regards,

Offline

#5 2015-07-25 23:15:49

Sarvadamana
Member
Registered: 2012-06-08
Posts: 14

Re: How do I get my computer to realize 2 comes before 10?

Thanks for moving it jason, I was debating between the two threads. Though to answer you question... I want them recognized that way in my entire GNU/Linux system.

nachosduyo, yes, that's what I am looking for, but I want that to happen across my whole GNU/Linux system by default for all programs (which is why I initially put this under GNU/Linux discussion).

I think this is a system issue, and that no one actually wants numbers sorted "10, 100, 132123, 2..." no matter the issue (I would love for someone to tell me a case where you would want this, I would be interested).

Offline

#6 2015-07-25 23:35:06

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: How do I get my computer to realize 2 comes before 10?

It depends on your collation settings, which are part of the locale.

$ sort -n n
!
@
a
A
b
B
2
10
100
132123
$ LC_ALL=C sort -n n
!
@
A
B
a
b
2
10
100
132123

Offline

#7 2015-07-25 23:39:21

Awebb
Member
Registered: 2010-05-06
Posts: 6,309

Re: How do I get my computer to realize 2 comes before 10?

Please read this document and return here, when you have absorbed and understood the information.

EDIT:

Fixed link.

Last edited by Awebb (2015-07-25 23:40:30)

Offline

Board footer

Powered by FluxBB