I'm trying to sort phrases such as the following:
a12_b7
a12_b11
a5_b3
a5_b30
a12_b10
using the numbers following the letters, lexicographically. For the example above, I expect the result to be:
a5_b3
a5_b10
a12_b7
a12_b11
a12_b30
Reading man sort
, I thought I had this figured out:
- Fields are delimited by underscores
- Two search keys
- First search key: first field, beginning with 2nd character in the field
- Second search key: second field, beginning with 2nd character in the field.
But - that does not work like I thought it would:
$ cat | sort --debug --key=1.2 --key=2.2 --field-separator=_
sort: text ordering performed using ‘en_IL.UTF-8’ sorting rules
a12_b10
______
__
_______
a12_b11
______
__
_______
a12_b7
_____
_
______
a5_b3
____
_
_____
a5_b30
_____
__
______
What have I gotten wrong? And what would be the appropriate sort
command-line in this case?
-n
option. I don't think "lexicographically" means what you think it means.