4

i'm looking for ways to sort a file of hex numbers like

C3
A2
3F

From the command line

linux solutions are welcome, though i'll be using windows and cygwin or gnuwin32.

barlop
  • 12,887
  • 8
  • 80
  • 109
  • Are we to assume from your example that all numbers have 2 digits and do not use lower case? – Dipstick Feb 13 '11 at 13:26
  • @Dipstick if you have a solution that assumes that, then that's still of interest. But regarding upper/lower case, I just found this http://slaptijack.com/system-administration/how-do-i-convert-to-uppercase-on-the-command-line/ $ echo waslowercase | tr '[a-z]' '[A-Z]' – barlop Feb 13 '11 at 13:37
  • `sort -f` does case-insensitive sorting, eliminating the need for passing your input through another command. – Prakash K Apr 28 '11 at 14:15

1 Answers1

3
matt@netbook:~$ sort
C3
A2
3F
^D
3F
A2
C3

Of course you can pipe to this command, or use any of it's options also.


Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
  • can you please include a full example so I can see it doing hex? 'cos I don't see a hex option. And is it doing hex or ascii? i'm not sure if they'd work out equivalent – barlop Feb 13 '11 at 13:28
  • yeah looks like no options required. And the ascii sort works for hex! – barlop Feb 13 '11 at 13:32
  • 3
    Ascii sort works for hex because numerals come immediately before the capital letters. If this answer were any more specific, it would lose its generality ;) I will add however, that you must be careful with hex numbers of differing lengths, but that's a separate question. – Matt Joiner Feb 13 '11 at 16:09