Sort array based on second column

Started by hdsouza, December 29, 2014, 02:05:16 PM

Previous topic - Next topic

hdsouza

Is it possible to sort an array based on the 2nd (or n th column)
A roundabout way would be rewriting the file, making the 2nd column into the 1st column, then sorting it and then writing it back the way the columns need to be placed, although I was hoping there was an easier way


Sorting it based on 1st column would be
Code (winbatch) Select

filarray_Unsorted =ArrayFileget(File_Unsorted)
ArraySort(filarray_Unsorted, @ASCENDING, 0, 0, ArrInfo(filarray_Unsorted,1)-1)
ArrayFileput(File_Sorted, filarray_Unsorted)

td

Simple enough. To sort on the second column

Code (winbatch) Select
ArraySort(filarray_Unsorted, @ASCENDING, 1)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hdsouza

Quote from: td on December 29, 2014, 02:19:34 PM
Simple enough. To sort on the second column

Code (winbatch) Select
ArraySort(filarray_Unsorted, @ASCENDING, 1)

I get Error 1830 - Sort column is out of range on ArraySort(filarray_Unsorted, @ASCENDING, 1)

td

Your array does not have 2 dimensions... I should have added that if your file has delimited columns then try using ArrayFilePutCsv to create a 2 dimensional array.  If your file has fixed length records and fixed length fields with a single key type you can just use BinarySort.  Full documentation for ArraySort, ArrayFilePutCsv and BinarySort can be found in the help file.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade