I am trying sort the text file using the UNIX sort
command (GNU 5.97 or 7.4) according to ASCII code. The lines in the file have a single column, which is used as the key in sort.
chr1:110170896:NM_004037:0:1:0/1
chr1:110170897:NM_004037:0:1:0/1
chr11:10325325:chr11:0:1:0/1
chr11::0325325:chr11:0:1:0/1
The ascii code of :
is 58, and 1
is 49. However, when I sort the file with sort -k 1,1 temp.txt
, the output is like this,
chr11::0325325:chr11:0:1:0/1
chr1:110170896:NM_004037:0:1:0/1
chr1:110170897:NM_004037:0:1:0/1
chr11:10325325:chr11:0:1:0/1
From the result, I have no idea how sort determines the order between 1
and :
. If there were any fixed order, the first and the forth lines should be placed together.
Ideally, I hope to sort the key from the left character to the right character according to the ASCII code.
You can always perform sort with argument -V to sort alphanumeric string.. You should mention that according to the manual, '-V' stands for "--version-sort" and is descrived as "natural sort of (version) numbers within text" -- taken from Ubuntu 20.04 standard repository.
5. -k Option: Unix provides the feature of sorting a table on the basis of any column number by using -k option. Use the -k option to sort on a certain column. For example, use “-k 2” to sort on the second column.
Sort-r command is used to sort the lines of data in a file in reverse order.
how about
sort -t : -k 1 filename
using the : as a field delimiter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With