I have a txt file with a list of 50 to 150 names in a random order, how can I create now file with the same names but listed alphabetically? I have all names converted to lowercase, and each name is on a seperate line.
ie....
blain
bev
malissa
kristen
darlene
trisha
renee
larry
kerry
curtis
keith
maryann
Thanx for any help in pointing me in the right direction,
Sort alphabetically
Moderators: Dorian (MJT support), JRL
- Marcus Tettmar
- Site Admin
- Posts: 7389
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
See the Bubble Sort script in Scripts 'n Tips:
http://www.mjtnet.com/forum/viewtopic.php?t=3414
So, just change inputfile and outputfile and try this:
http://www.mjtnet.com/forum/viewtopic.php?t=3414
So, just change inputfile and outputfile and try this:
Code: Select all
Let>inputfile=d:\names.txt
Let>outputfile=d:\names_sorted.txt
ReadFile>inputfile,NamesList
Separate>NamesList,%CRLF%,Names
Let>Max=Names_Count
GoSub>Bubble_Sort
//Write resultant list to a new file
IfFileExists>outputfile
DeleteFile>outputfile
Endif
Let>i=1
Repeat>i
Let>thisname=Names_%i%
WriteLn>outputfile,k,thisname
Let>i=i+1
Until>i=Max
Run>Notepad.exe %outputfile%
//Sorts Files_x array
//Set Max to number of elements
SRT>Bubble_Sort
Let>has_swapped=0
let>i=1
Repeat>i
Let>next=i+1
//change sign on next line to change direction of sort
if>Names_%i%>Names_%next%
Let>store=Names_%i%
Let>Names_%i%=Names_%next%
Let>Names_%next%=%store%
Let>has_swapped=1
endif
Let>i=i+1
Until>i=Max
If>has_swapped=1
GoSub>Bubble_Sort
Endif
End>Bubble_Sort
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Have used macro scheduler for a while and love it's capabilities but couldn't a simple DOS sort have done the same thing just as effieciently?
[/code]
Code: Select all
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd.exe /c sort test.txt /O testsort.txt
- Marcus Tettmar
- Site Admin
- Posts: 7389
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Ok, much easier!
As soon as I saw sort I thought of the bubble sort routine I wrote a while back. The DOS method didn't occur to me.
As soon as I saw sort I thought of the bubble sort routine I wrote a while back. The DOS method didn't occur to me.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- CyberCitizen
- Automation Wizard
- Posts: 721
- Joined: Sun Jun 20, 2004 7:06 am
- Location: Adelaide, South Australia
Just wanted to say thank you, I was looking for exactly this option today, to sort a list of Instructor Names. I could of looked at an ArraySort, however as the Instructor Names were already saved in a file & MS is doing the editing, it just means that a sort is run once when the file is saved and not on every launch.D_S wrote:Have used macro scheduler for a while and love it's capabilities but couldn't a simple DOS sort have done the same thing just as effieciently?
Code: Select all
Let>RP_WAIT=1 Let>RP_WINDOWMODE=0 Run>cmd.exe /c sort test.txt /O testsort.txt
Thanks again.
FIREFIGHTER