EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     sort lines according to their length
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
spiros
Posted on: 2/3/2013 6:03 am
Just popping in
Joined: 1/22/2010
From:
Posts: 7
sort lines according to their length
Is there a way to do that? I have a txt file tab separated with 10 columns and 100,000 rows. I tried this macro
http://www.emeditor.com/modules/newbb/viewtopic.php?topic_id=1961&forum=2 but gave me errors. I also tried Edit -> seperated values sort -> smallest to largest but the results were not good, i.e. not sorted according to length of line.





----------------
Greek translation

Yutaka
Posted on: 2/4/2013 9:59 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2423
Re: sort lines according to their length
Hello,

If you would like to sort according to length of line, you will have to write a macro to sort in that way. Would you like me to write sucn that macro? If so, please write the specification requirements for the macro. Thank you!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

spiros
Posted on: 2/5/2013 12:29 am
Just popping in
Joined: 1/22/2010
From:
Posts: 7
Re: sort lines according to their length
Thank you, I would appreciate it if you could. The specs is that it should be able to handle that specific file with 80 MB size, tab delimited with 10 columns, UTF-8 non-Latin text, and with line length ranging from 200 characters to 80,000.


----------------
Greek translation

Yutaka
Posted on: 2/5/2013 10:18 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2423
Re: sort lines according to their length
Hello,

Do you need to sort by line length of a specific column, or the length of a whole line?


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

spiros
Posted on: 2/5/2013 3:29 pm
Just popping in
Joined: 1/22/2010
From:
Posts: 7
Re: sort lines according to their length
Of whole line. Many thanks, much indebted.


----------------
Greek translation

Yutaka
Posted on: 2/7/2013 3:54 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2423
Re: sort lines according to their length
Hello,

This macro should sort the selected text from long to short.

document.selection.text = ((document.selection.text.split("\n")).sort(function(a,b){return b.length-a.length})).join('\n');



If you want to sort lines from short to long, please use this:

document.selection.text = ((document.selection.text.split("\n")).sort(function(a,b){return a.length-b.length})).join('\n');


Please select the whole document (CTRL + A) before you run this macro if you want to sort the entire document.

Thanks!


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

spiros
Posted on: 2/10/2013 2:12 pm
Just popping in
Joined: 1/22/2010
From:
Posts: 7
Re: sort lines according to their length
Wow, it worked in 2 seconds! Thank you so much.

Perhaps you could consider adding it as a sorting function in the "Separated values/Sort" menu item.


----------------
Greek translation

Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文