sorting ASCII string containing numbers


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers sorting ASCII string containing numbers
# 8  
Old 04-02-2009
Thanks for the suggestions! I think I finally figured out how the character position filed works.

I'm a bit confused though. I should be starting sorting at position 14 - right?

this works:

Code:
sort +1.14n

but this doesn't:

Code:
sort -nk 2.14

however, slight variation does work:

Code:
sort -nbk 2.14

it appears the leading blank character in the first column throws sorting off, so -b takes care of it. it almost makes sense, I'm saying "almost" because these work as well:

Code:
sort -nk 2.15
sort -nk 2.16

Perhaps I'm thinking too hard and missing something obvious?

Last edited by GKnight; 04-02-2009 at 04:32 PM..
# 9  
Old 04-24-2009
Hello guys, I have a problem sorting the following string(s):
data01_a0.txt
data01_a1.txt
data01_a2.txt
data01_b1.txt
data01_b2.txt
data01_b3.txt
data02_b10.txt
data02_a0.txt
data02_a1.txt
data02_a2.txt
data02_b4.txt
data02_b1.txt
data02_b11.txt
data02_b12.txt
data02_b2.txt
data02_b3.txt
data02_c0.txt
sorted:
data01_a0.txt
data01_a1.txt
data01_a2.txt
data01_b1.txt
data01_b2.txt
data01_b3.txt
data02_a0.txt
data02_a1.txt
data02_a2.txt
data02_b1.txt
data02_b2.txt
data02_b3.txt
data02_b4.txt
data02_b10.txt
data02_b11.txt
data02_b12.txt
data02_c0.txt

I could not figure out this sorting. sort +0.4n +0.8n filename seems to be the closest except it throws the file with c0 in it way higher directly after a0 string.
Any further ideas would be greatly appreciated.
Best regards, Peter

Last edited by peterd; 04-25-2009 at 02:41 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Convert ascii character values to number that comes between the numbers in UNIX

I have variable that contains multiple values of number and also include overpunch(i.e. # $ % etc) character so we want to replace it with numbers. here are the example: Code: 11500#.0# 28575$.5$ 527#.7# 42".2" 2794 .4 2279!.9! 1067&.7& 926#.6# 2279!.9! 885".5" 11714$.4$ 27361'.1'... (1 Reply)
Discussion started by: nadeemrafikhan
1 Replies

2. OS X (Apple)

Sorting scientific numbers with sort

Hey everybody, I'm trying to sort scientific numbers in a descending order using the command sort -gr <file>. It works fine on a Linux-Server, but doesn't on my macbook pro with OS X 10.10.3 (Yosemite). I tried to sort the following: 6.38e-10 6.38e-10 1.80e-11 1.00e-10 1.48e-12 And... (9 Replies)
Discussion started by: plebs
9 Replies

3. Shell Programming and Scripting

Help with Sorting numbers in a file

Hi Guys, Would appreciate some help on sorting numbers on a file using the sort command. I have tried this and it's not sorting properly. what am i missing? cat testing_sort 1:21 4:18 2:17 7:14 9:19 3:12 0:16 8:13 5:20 6:15 10:11 sort -t: -nk1,1 -nk2,2 testing_sort (4 Replies)
Discussion started by: Apollo
4 Replies

4. Shell Programming and Scripting

Sorting mixed numbers and letters

Hello, I have a file such as this: chr1 chr2 chr1 chr2 chr3 chr10 chr4 chr5 chrz chr1AI want to sort it, I use this command: sort -k1 -th -n testfilebut I get this output, how can I fix this? chr1 chr1 chr10 chr1A chr2 chr2 (3 Replies)
Discussion started by: Homa
3 Replies

5. Shell Programming and Scripting

Sorting numbers containing symbols

hi all, i need help on sorting data. i have a file as below /home/oracle $ cat 234.txt +1234 -2356 -1001 +231 0023 -0987 +19000 65487 6 after sorting i want the output as below -2356 -1001 (2 Replies)
Discussion started by: mahesh1987
2 Replies

6. UNIX for Dummies Questions & Answers

sorting numbers with sort -n

Looking for help for sort, I learned that for sorting numbers I use: sort -n but it seems that that is not enough when you have numbers like 0.2000E+7 for example, sort -n will not worry about the E+7 part, and will just sort the numbers like 0.2000. Exapmle: cat example.txt .91000E+07... (9 Replies)
Discussion started by: cosmologist
9 Replies

7. UNIX for Dummies Questions & Answers

Sorting data in an ASCII file

Hi,,, is there anyway to sort the data that I have on an ASCII file, using unix? :confused::confused::confused: Thanks (2 Replies)
Discussion started by: cosmologist
2 Replies

8. Shell Programming and Scripting

ascii sorting in unix

Hi all i am facing a problem in sorting command. The script depending on the sorting command works fine only if ascii sorting is done. i need to know how to find out how to perform ascii sorting. sorting is case insensitive in my file has data in the following format. AA/BB/ AAA/BB\ also... (1 Reply)
Discussion started by: sais
1 Replies

9. UNIX for Dummies Questions & Answers

sorting an ascii file

I would like to sort a large ascii file. Primary sort on the 1st column, and secondary sort on the second column. The file consists of 10 rows of header text and then thousands of rows with 6 columns. I want to sort all of the rows by the first column and second column. As an example, here is... (2 Replies)
Discussion started by: shes
2 Replies

10. Shell Programming and Scripting

Trouble sorting numbers embedded

Hi All, First time poster. I have a text file that as many entries like below (single line): egrep RspTime conlb.txt |more S(xxx.xxx.xxx.xxx:5050:UP) Hits(13358983, 2/sec, P) ATr(2) Mbps(0.07) BWlmt(0 kbits) RspTime(16.50 ms) ... I am trying to sort on the RspTime from highest to lowest... (4 Replies)
Discussion started by: mycrew2008
4 Replies
Login or Register to Ask a Question