EN
Linux - how to sort alphanumeric strings
5 points
With Linux sort command we can sort with argument -V to sort alphanumeric string.
xxxxxxxxxx
1
$ sort -V input_file.txt > output_file_2.txt
xxxxxxxxxx
1
$ cat input.txt
2
ABC_2
3
ABC_11
4
ABC_1
5
ABC_12
6
ABC_22
7
ABC_5
8
ABC_3
9
ABC_21
10
11
# simple sort
12
$ sort input_file.txt > output_file_1.txt
13
14
$ cat output_file_1.txt
15
ABC_1
16
ABC_11
17
ABC_12
18
ABC_2
19
ABC_21
20
ABC_22
21
ABC_3
22
ABC_5
23
24
# sort alphanumeric string with argument -V
25
$ sort -V input_file.txt > output_file_2.txt
26
27
$ cat output_file_2.txt
28
ABC_1
29
ABC_2
30
ABC_3
31
ABC_5
32
ABC_11
33
ABC_12
34
ABC_21
35
ABC_22