Jump to content
Macro Express Forums

How To: Sort Lines Of Text Or Numbers In A File


Recommended Posts

For those really big sorting jobs that I keep reading about here in the forum ...

 

This example macro is a companion to the original {Single Dimension Sort} macro, which sorts strings, or strings of numbers from a variable instead of a file. This script reads lines from text file and converts them into an array for sorting. Each element in the array is a line of text (or numbers) in the text file. A line ends with a CR/LF.

 

Included is a file that contains 50,000 random lines of text and another containing 50,000 random numbers. But, feel free to create your own files for testing. My computer (2.4ghz) sorts the 50,000 word file in about 9 seconds, which includes reading the data from the input file and writing the sorted array back to the output file.

 

Because this example generates a VBS script which does the sorting, you only need to import the attached playable (.mxe) file into any Macro Express library (.mex) file. Nothing else is required to use the sorting algorithm. There are no external files except, of course, the file that you want to sort!

 

The attached macro is well documented. Please review the header section within it for information on the sorting options, which are:

  • Sort all or only part of the file
  • Sort using case or ignore case
  • Sort in ascending or descending order

SingleDimensionSort_File.zip

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...