Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort a text file according to character code or ASCII code value?

Tags:

I would like to sort lines of text according to character code or ASCII code value by command line. I tried the following command line but the result is not what I expected.

# string="   8888888 >' > Transportation > Temp >temp >TEMP >    99 >    Temp >  Temporary" # LC_ALL=C echo "$string" | sort  '    8888888     99 temp  Temp     Temp TEMP   Temporary  Transportation 

To sort according to ASCII code value, the output should look like

    99     Temp    8888888   Temporary  Temp  Transportation ' TEMP temp 

Does anyone know how to do that?

like image 878
While Loop Avatar asked Mar 14 '11 08:03

While Loop


People also ask

How do I get the ASCII code for a character?

Program to Print ASCII ValueThe character is stored in variable c . When %d format string is used, 71 (the ASCII value of G ) is displayed. When %c format string is used, 'G' itself is displayed.

What is the ASCII value of A to Z?

Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.


1 Answers

You've frobbed the wrong program.

echo "$string" | LC_ALL=C sort 

Using $LC_COLLATE is also acceptable.

like image 150
Ignacio Vazquez-Abrams Avatar answered Sep 22 '22 21:09

Ignacio Vazquez-Abrams