This may be a more esoteric question than this list can help me with, but hopefully someone can at least point me to somewhere to find an answer.

I’m dealing with a list of filenames that were automatically generated as 24-digit hexadecimal numbers. When they are sorted in a normal alphanumeric sort (such as by the Finder), they aren’t sorted by hex value, but as alphanumeric text. This results in a different order from by actual value. I want them sorted by numeric value.

I’ve been trying to find something (free, low cost, or that I already have) that can batch process these to sort by value, either directly as hex values or with a conversion to decimal. The problem is twofold: one, as I mentioned, they’re 24 digits, which represents a value much higher than most consumer-level products (such as Excel) can handle (in decimal they run into 29 digits, tens of octillions); and two, there’s nearly 5000 of these files, which means converting the numbers one at a time (such as with a calculator) would be a Herculean task.

The filenames were not generated strictly in numeric order chronologically (that is, most of them would be in order by date, but there are a few hundred scattered filenames that for some reason didn’t follow order), so sorting the files by date doesn’t get around the problem.

You don’t need to convert the entire 24-digit hexadecimal string to one large number to sort it. You can break it into smaller strings, such as four six-digit strings, convert each to a numeric value, then sort by multiple numeric fields.

The “sort” command should do what you want, assuming the values are stored in ASCII, because in ASCII a-f and A-F all have ASCII code values greater than 0-9.

Finder sorts names differently. Finder extracts digits in the range of 0-9, finds the value (ignoring leading zeros) and groups such files together. Finder and sort display the following order:

Finder (Finder sorts as) sort
10a. 10, then a 100
19a 19, then a 10a
100. 100 19a

Here’s a simple sort command, assuming the data is in file in.txt and you want to output to file out.txt.

sort -f < in.txt > out.txt

(The -f option ignores case, so A and a are considered the same.)
Type “man sort” into Terminal to get a full list of options.

That might work for you. And for those with extensive terminal experience I’m sure there’s a way to do this…but I would not be included in that definition of “those” unfortunately.