Skip to main content
Inspiring
March 29, 2023
Question

Sorting Index by first n-digits

  • March 29, 2023
  • 3 replies
  • 888 views

An index with 20k codes has to be sorted differently, considering only the first n (7 in my cae) digits.

Codes has variable number of digits (from 7 to 12 or more). I just need to order them ignoring anything above the 7th digit.

Thanks for help

This topic has been closed for replies.

3 replies

Robert at ID-Tasker
Legend
March 29, 2023

What do you mean by Index? 

 

If a list of codes - single code per line - the quickest way would be to copy to Excel, sort and paste back. 

 

If there is more info associated with the code - it will be more complicated - but of course perfectly doable 😉 

 

FRIdNGE
March 29, 2023

Hi,

 

Just a simplistic Script that includes in each entry a "sort by" as: the 7 first digits!

 

Best,

(^/)  The Jedi

FRIdNGE
March 29, 2023

… Well! Something like this:

 

index with basically sorted (ID by default) entries:

 

 

What the op seems to want:

 

 

As you can see, the numbers are sorted basing on the first seven digits!

 

(^/)

Gioyer07Author
Inspiring
March 29, 2023

Thank you although I can't figure out how it works. You use only the  expression and there's no need to specify how many digits do you need? Well in my case the summary has produced a column with all the 20k lines as in the example hereunder:

In the meanwhile I tested SmartSort (https://indiscripts.com/category/projects/SmartSort)

It's a freeware and works much faster than the bundled Indesign's sorting javascript.

Although it has some customization options for the text, there's almost none when dealing with numbers.

The script's result (applied after objects cleansing) seems quite correct even without specifying the desired "n" value.

I have to test it deeper to see it's behaviour whith the tiny "new" object between the code and the page number.

James Gifford—NitroPress
Legend
March 29, 2023

This may be achievable with a script, but in my experience, very specialized tasks like this are better done by tools outside InDesign. Without knowing anything further, I'd use something like Excel to sort the list; just possibly Word.

 

Gioyer07Author
Inspiring
March 29, 2023

Sorting is a built in script but it's quite basic as it lacks a function window wherr one could specify a filter to apply before sorting. Does anybody know about a better script? Going outside Indesign is a bad idea as many styles and objects applied would go... fishing.

James Gifford—NitroPress
Legend
March 29, 2023

ID scripts can be made quite complex and could probably handle it (I am a fledgling script guy at best, so I'm not the one to help with it.) My only concern is that 20,000 items is a lot, at least for InDesign... many of its capabilities have either modest data spans or slow way down past certain limits. Not sure if this one of those or not.

 

Some of the scripting gurus should check in soon on this. If not, I'll bump it to get their attention.