|
sorting ASCII string containing numbers
I have the following output where I need to sort the second column numerically (starting with IBMULT3580-TD 10 and ending in IBMULT3580-TD 123)
Code:
Drv DriveName
0 IBMULT3580-TD13
1 IBMULT3580-TD18
2 IBMULT3580-TD14
3 IBMULT3580-TD10
4 IBMULT3580-TD11
5 IBMULT3580-TD17
6 IBMULT3580-TD117
7 IBMULT3580-TD121
8 IBMULT3580-TD15
9 IBMULT3580-TD112
10 IBMULT3580-TD115
11 IBMULT3580-TD111
12 IBMULT3580-TD116
13 IBMULT3580-TD12
14 IBMULT3580-TD113
15 IBMULT3580-TD19
16 IBMULT3580-TD118
17 IBMULT3580-TD16
18 IBMULT3580-TD123
19 IBMULT3580-TD119
20 IBMULT3580-TD120
21 IBMULT3580-TD110
22 IBMULT3580-TD114
23 IBMULT3580-TD122
I'm trying to apply the sort, and the output is getting sorted, but not numerically:
Code:
`some_command` |sort -k 2
3 IBMULT3580-TD10
21 IBMULT3580-TD110
11 IBMULT3580-TD111
9 IBMULT3580-TD112
14 IBMULT3580-TD113
22 IBMULT3580-TD114
10 IBMULT3580-TD115
12 IBMULT3580-TD116
6 IBMULT3580-TD117
16 IBMULT3580-TD118
19 IBMULT3580-TD119
4 IBMULT3580-TD11
20 IBMULT3580-TD120
7 IBMULT3580-TD121
23 IBMULT3580-TD122
18 IBMULT3580-TD123
13 IBMULT3580-TD12
0 IBMULT3580-TD13
2 IBMULT3580-TD14
8 IBMULT3580-TD15
17 IBMULT3580-TD16
5 IBMULT3580-TD17
1 IBMULT3580-TD18
15 IBMULT3580-TD19
I tried adding -n but it produces a rather weird output, seemingly in random order. Any suggestions how to sort this string numerically? I can't figure it out from the sort man page. TIA!
|