antica Posted August 25, 2005 Report Share Posted August 25, 2005 Hi Just wondering if any experts can help. I have this text file (assumed sorted from col 1 onwards) that I need to be sorted from the group with the most number of lines to the group with the least number of lines. I was wondering if ME can help me to do that?? Group here defined as having same chars from col. 1 to col. 10. Eg. aaaaaaaaaadfkdflsfkfg aaaaaaaaaakddfkdfkrddldf aaaaaaaaaandfjdfk aaaannnnnnfdfjrfj aaaannnnnnhsdjeje aaaannnnnnndfejrejr aaaannnnnnxjdrjdrj aaaannnnnnzkdfkdfk bbbbbbbbbbakdfjkdf bbbbbbbbbbkjdfjdf ccccnnnnnndsfjdfjdfj ccccnnnnnnekrekr33 ccccnnnnnnfkrkrrerjkrek ccccnnnnnnoekrjfjd ccccnnnnnnjerjerj ccccnnnnnnkdfkdfkdf ccccnnnnnnmkfdkfdfk ccccnnnnnntdfldfker ccccnnnnnnxkrk ccccnnnnnn - 9 lines bbbbbbbbbb - 2 lines aaaannnnnn - 5 lines aaaaaaaaaa - 3 lines After sorting, I want the group of ccccnnnnnn to be on the 1st line of the text file, and then the group of aaaannnnnn to be on the 10th line, and aaaaaaaaaa to be on the 15th line and finally bbbbbbbbbb to be on the 17th line of the text file. I don't care how the 11th column onwards are sorted (within the group or within the file). What's essential is that the groups are sorted. Anyone know if this is achievable thru' a macro in ME? Basically, what I'm doing currently is do a search/replace of the 1st 10 chars to get the no. of lines (same for find and replace field). After knowing the no. of lines, I prepend the no. of lines to the replace text. i.e. First find = "ccccnnnnnn", replace = "ccccnnnnnn"; count = 9 then find = "ccccnnnnnn", replace = "009ccccnnnnnn" then repeat for the other groups. After doing for all the groups, I then sort in descending order the first 3 chars (which now contains the no. of lines), then remove the first 3 chars in block mode. Tedious but only way I can think of doing this task. Any smart people able to code this in a macro? Will really appreciate it Quote Link to comment Share on other sites More sharing options...
jowensii Posted August 25, 2005 Report Share Posted August 25, 2005 Check out the "How To: Sort Strings Or Numbers " topic Quote Link to comment Share on other sites More sharing options...
randallc Posted August 28, 2005 Report Share Posted August 28, 2005 Hi, The topic referred to in that one is a different thread; Almost Sorting, Ordering Lines in a Text File I think this would help; "GROUPING ALGORITHM" Best, Randall Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.