Jump to content
Macro Express Forums

Group Sorting In A Text File?


antica

Recommended Posts

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 :D

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...
×
×
  • Create New...