Sort hexadecimal numbers of different lengths from command line?

If I have a file of hexadecimal numbers of different lengths, for example.

1F
b
c

How can I sort them from the command line?

Linux solutions are welcome, although I will use windows and cygwin or gnuwin32.

Note: I explicitly cannot use SORT 'cos, which will save them in the order that is incorrect.

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

This saves the original upper / lower case hexadecimal numbers.

+6
source

Give it a try sort -n filename. The flag -naccording to the manual page "is compared by the numerical value of the string."

: @barlop, -n .

0

You can use awk script to create a file that left lines at a fixed length, sort the resulting file, and split leading spaces into result.

Some time has passed since I used awk, but, as I recall, it was not difficult to get everything right justified.

0
source

Source: https://habr.com/ru/post/1792606/


All Articles