Sort alphabetically

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
GarryP
Junior Coder
Posts: 27
Joined: Sat Feb 04, 2006 12:01 pm

Sort alphabetically

Post by GarryP » Wed Aug 29, 2007 6:30 pm

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,

User avatar
Marcus Tettmar
Site Admin
Posts: 7389
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 29, 2007 6:39 pm

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:

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?

GarryP
Junior Coder
Posts: 27
Joined: Sat Feb 04, 2006 12:01 pm

Thank you

Post by GarryP » Wed Aug 29, 2007 7:02 pm

Works like a charm. I searched to forum for 2 days, and just couldnt find the answer, so when all else fails, ask the pro's. Thanx again.

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Wed Aug 29, 2007 7:51 pm

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
[/code]

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 29, 2007 8:23 pm

Bravo D_S! Macro Scheduler (my favorite software) enhances DOS capabilities as well as VBScript capabilities

I too like DOS... Have I said that before? :wink:

User avatar
Marcus Tettmar
Site Admin
Posts: 7389
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 29, 2007 8:27 pm

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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon May 27, 2013 4:42 am

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
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.

Thanks again.
FIREFIGHTER

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon May 27, 2013 8:36 am

CyberCitizen wrote:Just wanted to say thank you, I was looking for exactly this option today, to sort a list of...
Me too. This time, DOS' sorting speed should defeat Marcus' bubble sort.
Thanks, D_S.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts