William LAM William LAM - 1 month ago 10
Bash Question

How to sort alphabet first and then numeric in unix

Suppose I have a file containing 1 column:

1
2
a
b
0


The expected outcome:

a
b
0
1
2


If I use sort alone, the outcome would become 1->2->a->b which is not I want.
Is there any way I can sort alphabet first and then numeric? Thanks.

PS. PS.
Answer
sort -g <inputfile
a
b
0
1
2

Additional example:

cat inputfile
1
0
2
3
sd
35
76
23
asd


sort -g inputfile
asd
sd
0
1
2
3
23
35
76