sort command is case insensitive...alternatives?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

sort command is case insensitive...alternatives?

#1 Post by catalinnc » 17 Oct 2015 13:07

hi...


on my win xp sp2 this line

Code: Select all

sort text.txt /o text.txt


makes a sorting that is case insensitive...

this is not good because i need to do a (de)dupe of the result with a case sensitive script...

content of text.txt is

Code: Select all

name1
name2
name3
NAME3
NAME2
NAME1
name3
name2
name1
NAME1
NAME2
NAME3


and the sorted text_sorted.txt is

Code: Select all

NAME1
name1
NAME1
name1
name2
NAME2
NAME2
name2
name3
NAME3
NAME3
name3


so a need a speedy alternate solution (maybe some batch with java?)


respect...
_

p.s. to be perfect clear i need a sorted result like

Code: Select all

name1
name1
NAME1
NAME1
name2
name2
NAME2
NAME2
name3
name3
NAME3
NAME3


or

Code: Select all

NAME1
NAME1
name1
name1
NAME2
NAME2
name2
name2
NAME3
NAME3
name3
name3

_

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: sort command is case insensitive...alternatives?

#2 Post by Aacini » 17 Oct 2015 14:54

Just use the undocumented /C switch:

Code: Select all

C:\> sort /C test.txt
name1
name1
NAME1
NAME1
name2
name2
NAME2
NAME2
name3
name3
NAME3
NAME3

Tested on Windows 8.1

Antonio

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: sort command is case insensitive...alternatives?

#3 Post by einstein1969 » 17 Oct 2015 15:19

Nice find. Work on windows 7 too.

Einstein1969

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: sort command is case insensitive...alternatives?

#4 Post by npocmaka_ » 17 Oct 2015 17:03

Aacini wrote:Just use the undocumented /C switch:
...
Antonio


Great finding :!:

The full version version of the switch is /case_sensitive

There's one more undocumented switch /u or /uni_output which will out put in unicode.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: sort command is case insensitive...alternatives?

#5 Post by Aacini » 17 Oct 2015 19:06

Yes. Taken from sort.exe file:

Code: Select all

%s  %s case_sensitive  locale  memory  output  reverse record_maximum  temporary       uni_output  C   TEMP path   srt

Antonio

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: sort command is case insensitive...alternatives?

#6 Post by Samir » 18 Oct 2015 08:47

Neat! Anyone tested this under xp?

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: sort command is case insensitive...alternatives?

#7 Post by npocmaka_ » 18 Oct 2015 08:57

Samir wrote:Neat! Anyone tested this under xp?


/c works /u does not

catalinnc
Posts: 39
Joined: 12 Jan 2015 11:56

Re: sort command is case insensitive...alternatives?

#8 Post by catalinnc » 18 Oct 2015 11:09

Aacini wrote:Just use the undocumented /C switch:

Code: Select all

C:\> sort /C test.txt
name1
name1
NAME1
NAME1
name2
name2
NAME2
NAME2
name3
name3
NAME3
NAME3

Tested on Windows 8.1

Antonio


working great on win xp sp2 too...thanks a lot...

respect...
_

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: sort command is case insensitive...alternatives?

#9 Post by dbenham » 21 Oct 2015 22:59

:shock: Whoa! I've always wanted a case sensitive sort, and the undocumented /C option has been there all along :!: :roll:

Stupid MicroSoft :evil:

Great find Aacini, thanks :D


Another option is to use my JSORT.BAT utility. If all you need is case sensitive, then SORT /C is probably your best bet. But JSORT has a number of additional features you may be interested in.


Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: sort command is case insensitive...alternatives?

#10 Post by foxidrive » 22 Oct 2015 07:18

dbenham wrote::shock: Whoa! I've always wanted a case sensitive sort, and the undocumented /C option has been there all along :!: :roll:

Stupid MicroSoft :evil:

Great find Aacini, thanks :D


It is a good find - but the thought that pops into my head is that the routine may not yet be robust, and is why the switch wasn't made public.

You'd think that a non-robust routine would have been removed - but we never know...

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: sort command is case insensitive...alternatives?

#11 Post by Squashman » 22 Oct 2015 07:31

Anyone got Windows 10 so they can look at the help file to see if they added it.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: sort command is case insensitive...alternatives?

#12 Post by npocmaka_ » 22 Oct 2015 07:44

Squashman wrote:Anyone got Windows 10 so they can look at the help file to see if they added it.


It's not added in the help.
That's why I looked at sort.exe with strings.exe to see if there's something else undocumented.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: sort command is case insensitive...alternatives?

#13 Post by Samir » 22 Oct 2015 08:59

Anyone want to stress test the undocumented switch? That should give us some idea if it's faulty, and if so, where.

Post Reply