Do the groups of lines with numbers break at the lines with text? In other words, do you only sort the numbers up to "test" as a group, and then sort the next set of lines with numbers until the next line with "test" or does the sorting of the numbers need to be done as one continuous group?
If the lined numbers are discrete groups you can continue storing them in an array until you get to a line with text. You then sort the group of numbers and print them to a file and then print the line of text last, or push it all into a larger array and continue like this this until the entire file is read and sorted.
If the entire file needs to be sorted yet the lines with text need to stay in their original position you will need to store the position (the line number I guess) in a hash, then sort all the numbered lines, then print the sorted numbers back to the file but keeping track of the line numbers as you go and insert the text back as needed.
But one thing I am pretty sure of, you will not be able to accomplish this with a single sort.
Last edited by KevinADC; Aug 17th, 2009 at 12:33 pm.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
Offline 898 posts
since Mar 2006