Hi, I'm having this idea to accomplish a task by sorting the lines of a file according to their length.
The file or files I will be using are probably 500Kb or more. And I wonder if autohotkey would be able to handle this or if someone knows one of those little command line programs that could do this, could you please point me too?
Thanks!

sort a text file according to line length
Started by
edu
, Nov 06 2007 07:59 PM
4 replies to this topic
that should not be a big problem. worst case you make a list of lines and lengths, then sort that, and read the final file in that order into another file.
#2
-
Posted 06 November 2007 - 08:10 PM

Thanks enguneer. Sounds like a good idea. I'll try to parse the file adding the line length at the beginning of each line, then I will sort it.
Thanks for the pointer, again.
Thanks for the pointer, again.
#3
-
Posted 06 November 2007 - 09:46 PM

Use the F option of sort. 

FileRead, text, %A_ScriptFullPath% Sort, text, F SortFunc MsgBox %text% SortFunc(lineA, lineB, offset) { ; Return positive if lineA is longer than line B. ; Return negative if lineA is shorter than line B. if StrLen(lineA) != StrLen(lineB) return StrLen(lineA)-StrLen(lineB) ; Use offset to try to preserve the order in the file when two lines are of equal length. return -offset }I had to laugh when I saw the result. :lol:
#4
-
Posted 07 November 2007 - 03:41 AM

Wow. Drooling!
Man, you guys are amazing. Thank you very much!
I wonder why. Anyway, when I just tested your script I had an impression that something was wrong, but no... it was doing what was supposed to do :wink: Great. I could help smiling.
Cheers,
Eduardo
Man, you guys are amazing. Thank you very much!
I had to laugh when I saw the result. Laughing
I wonder why. Anyway, when I just tested your script I had an impression that something was wrong, but no... it was doing what was supposed to do :wink: Great. I could help smiling.
Cheers,
Eduardo
#5
-
Posted 07 November 2007 - 07:33 PM

The best things of life are free.