Windows – Sort hexadecimal numbers of different lengths from the command line?

Sort hexadecimal numbers of different lengths from the command line?… here is a solution to the problem.

Sort hexadecimal numbers of different lengths from the command line?

If I have a file with hex numbers of different lengths, for example

1F
b
c

How do I sort them from the command line?

Welcome to Linux solutions, but I’ll use Windows and cygwin or gnuwin32.

Note: I obviously can’t use SORT ‘cos to keep them out of order is wrong.

Solution

cat thefile | while read line; do printf "%d %s\n" "0x$line" "$line"; done | sort -n | awk '{print $2}'

This preserves the original case of hexadecimal numbers.

Related Problems and Solutions