15 Replies Latest reply on Jul 13, 2014 12:29 PM by Cumanacaro

# How to order a list of words by increasing (or decreasing) number of letters?

The idea is obtain this:

a

an

at

bar

bis

bus

fish

rules

wolves

It is possible?

• ###### 1. Re: How to order a list of words by increasing (or decreasing) number of letters?

it was possible, but has a limitation

• ###### 2. Re: How to order a list of words by increasing (or decreasing) number of letters?

can you tell me if between words has a return?

• ###### 3. Re: How to order a list of words by increasing (or decreasing) number of letters?

use find-change by list:

findWhat: "(\\b[\\u\\l]{1}\\b)"

changeTo: \$1

findWhat: "(\\b[\\u\\l]{2}\\b)"

changeTo: \$2

findWhat: "(\\b[\\u\\l]{3}\\b)"

changeTo: \$3

findWhat: "(\\b[\\u\\l]{4}\\b)"

changeTo: \$4

findWhat: "(\\b[\\u\\l]{5}\\b)"

changeTo: \$5

findWhat: "(\\b[\\u\\l]{6}\\b)"

changeTo: \$6

findWhat: "(\\b[\\u\\l]{7}\\b)"

changeTo: \$7

findWhat: "(\\b[\\u\\l]{8}\\b)"

changeTo: \$8

findWhat: "(\\b[\\u\\l]{9}\\b)"

changeTo: \$9

you can inspire by this idea

• ###### 4. Re: How to order a list of words by increasing (or decreasing) number of letters?

Hi John,

Do you think to SortParagraphs.jsx? Works cool to do it.

• ###### 5. Re: How to order a list of words by increasing (or decreasing) number of letters?

no idea

• ###### 6. Re: How to order a list of words by increasing (or decreasing) number of letters?

Apparently not! And besides, it's free and installed by default!

• ###### 7. Re: How to order a list of words by increasing (or decreasing) number of letters?

can you directly reply to original discussion, no need to reply to me,

• ###### 10. Re: How to order a list of words by increasing (or decreasing) number of letters?

I just give an idea, if you have another one better then me you can reply to Cumanacaro

• ###### 11. Re: How to order a list of words by increasing (or decreasing) number of letters?

THe example is sorted by the length of words, and words with the same length are sorted alphabetically. BUT the entire list is ALSO sorted alphabetically! Is that purely a coincidence? Please give a better example...

• ###### 12. Re: How to order a list of words by increasing (or decreasing) number of letters?

Hi Jongware,

Maybe you're right finally! …

This approach can be easily fixed with Grep (2 click, using Multi-Find/Change) and SortParagraphs.jsx too. But if you can write a [JS] to do this in … 15 min. in 1 click (not 3!), maybe Javascript is a better solution! ( )

• ###### 13. Re: Re: How to order a list of words by increasing (or decreasing) number of letters?

(Looking at the clock), okay, that took 3 minutes.

Select the list (which should have hard returns at each line), run this script. Done.

```words = app.selection[0].contents.split('\r');
words.sort (function(a,b) { return a.length == b.length ? a.toLowerCase().localeCompare(b.toLowerCase()) : a.length - b.length; });
app.selection[0].contents = words.join('\r');
```

A before/after image:

• ###### 14. Re: Re: How to order a list of words by increasing (or decreasing) number of letters?

Aha! Jongware wins! I knew you would write it quickly! Great! Nothing else to say!    [Thanks, I save it in my useful scripts folder!]

• ###### 15. Re: How to order a list of words by increasing (or decreasing) number of letters?

@ john and @jong;

Really, thanks a lot.

I am so sorry because I had to be absent the whole weekend...

I think grep and script methods are valid.

The scripting one perhaps deserves the correct answer as is not choice to qualify both as perfect...

Deliberately I proposed also alphabetically, and in the end  the idea is to use this method also to make some search in grep with pipes, where the shortest matches should be placed in first place ( fig.| figure, for example)