William LAM - 4 months ago 30

Bash Question

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.

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
```