1

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?

2
  • 1
    What result are you expecting? Commented Aug 7 at 14:06
  • Look into the -n option. I don't think "lexicographically" means what you think it means. Commented Aug 7 at 15:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.