Languages
[Edit]
EN

Linux - how to sort alphanumeric strings

5 points
Created by:
Hiba-Tate
488

1. Overview

With Linux sort command we can sort with argument -V to sort alphanumeric string.

$ sort -V input_file.txt > output_file_2.txt

2. Sort alphanumeric string example

$ cat input.txt
ABC_2
ABC_11
ABC_1
ABC_12
ABC_22
ABC_5
ABC_3
ABC_21

# simple sort
$ sort input_file.txt > output_file_1.txt

$ cat output_file_1.txt
ABC_1
ABC_11
ABC_12
ABC_2
ABC_21
ABC_22
ABC_3
ABC_5

# sort alphanumeric string with argument -V
$ sort -V input_file.txt > output_file_2.txt

$ cat output_file_2.txt
ABC_1
ABC_2
ABC_3
ABC_5
ABC_11
ABC_12
ABC_21
ABC_22

3. Sort alphanumeric string example with screenshot

Screenshot of Linux sort command - sort vs sort alphanumeric string - sort -V - https://dirask.com/q/9pYmzp
Screenshot of Linux sort command - sort vs sort alphanumeric string (sort -V)

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Linux

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join