Solved How to do this in cmd? (Make orderly numbers in batch file)

January 25, 2016 at 09:19:28
Specs: Windows 7, i3-2120 3.30 GHz / 4 GB
Hello,
I have made a code in CMD that gives you random numbers between 1 to 37
I get them not in order
Example: (36, 1, 5, 25, 16, 12)

I want do a command that place them fro the lower one to the higher one (in order)
Example: (1, 5, 12, 16, 25, 36)

I have tried a lot but still got an error.

Someone know how to do this code?


See More: How to do this in cmd? (Make orderly numbers in batch file)

Report •


✔ Best Answer
January 26, 2016 at 18:36:11
mmc was right, using SORT is much easier than trying to use batch. You can use SORT to sort your variables, but a lot depends on what you want to do with the data, since this only displays it. Also, this depends on using variables with a "tag", in this case _ underscore. Also, you must at some point pad your values, or else single digits will come out-of-order with double-digits. The pad-character doesn't matter for sorting.
The "tag" character also does not matter - it is simply used to isolate a subset of variables to submit to the sort. this example uses underscore for the tag and space for the pad:

@echo off & setlocal enabledelayedexpansion
set _a=10
set _b= 9
set _c= 2
set _d= 8
set _e= 4
set _f= 6
set _| sort /+3
:: now show the variales names with their values:
for /f "tokens=1,2 delims==" %%a in ('set _^|sort /+3') do echo %%a %%b



#1
January 25, 2016 at 10:58:19
It's been some time since I did any batch programming,
but isn't there a SORT command?

http://www.computerhope.com/sorthlp...

MIKE

http://www.skeptic.com/


Report •

#2
January 25, 2016 at 23:11:05
Do you know how to do something like this?
I set A, B, C, D, E, F are random numbers between 1-37.
Every time I run the batch program and don't know how much is A and how much is E (for example).
A can be 37 and E can be 15.
How can I do a command that order them from the lower number 1 to to higher 37?
Another example: A=26, B=4, C=18. That is the random numbers I got, I don't know them but I need to order them without know the numbers (A,B,C -> B,C,A (26,4,18 -> 4,18,26))

Thanks.

Report •

#3
January 26, 2016 at 06:45:30
Sorry, like I said, it's been a long time since I did any batch programming,
hopefully, some one with more expertise will offer a suggestion.

Good luck.

MIKE

http://www.skeptic.com/


Report •

Related Solutions

#4
January 26, 2016 at 18:36:11
✔ Best Answer
mmc was right, using SORT is much easier than trying to use batch. You can use SORT to sort your variables, but a lot depends on what you want to do with the data, since this only displays it. Also, this depends on using variables with a "tag", in this case _ underscore. Also, you must at some point pad your values, or else single digits will come out-of-order with double-digits. The pad-character doesn't matter for sorting.
The "tag" character also does not matter - it is simply used to isolate a subset of variables to submit to the sort. this example uses underscore for the tag and space for the pad:

@echo off & setlocal enabledelayedexpansion
set _a=10
set _b= 9
set _c= 2
set _d= 8
set _e= 4
set _f= 6
set _| sort /+3
:: now show the variales names with their values:
for /f "tokens=1,2 delims==" %%a in ('set _^|sort /+3') do echo %%a %%b


Report •


Ask Question