Languages
[Edit]
EN

Linux - how to sort alphanumeric strings

5 points
Created by:
Kate_C
2845

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)

 

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍