![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sort directory with complex numeric file names | fdsayre | UNIX for Dummies Questions & Answers | 2 | 04-15-2009 02:12 AM |
| Non Numeric Argument Error | Allenzo | UNIX for Dummies Questions & Answers | 4 | 08-04-2008 11:40 AM |
| :-) 1213: Character to numeric conversion error. Plz help | anushree.a | Shell Programming and Scripting | 2 | 07-08-2008 12:50 AM |
| help newb at linux and bash need numeric script sort | dlm1065 | Shell Programming and Scripting | 1 | 04-27-2008 05:11 AM |
| how to numeric sort on field time | rahulspatil_111 | Shell Programming and Scripting | 1 | 04-27-2007 12:52 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Numeric sort error
Hello all
I have data like below where the column with values (PRI, SEC ) is the char field and the rest are Numeric Fields. 200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51 200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51 200707,9580,58,7,2,1,PRI,1,1,138,204173,0,5,10,-58.51,-58.51 200707,9580,58,7,2,1,SEC,1,1,138,204173,0,5,10,-58.51,58.51 200707,9580,58,7,2,1,PRI,1,1,139,170842,0,5,10,-25.98,-25.98 200707,9580,58,7,2,1,SEC,1,1,139,170842,0,5,10,-25.98,25.98 When i did sort on the above data using the below command: sort -n -t',' +0 -1 +1 -2 +2 -3 +3 -4 +4 -5 +5 -6 +6 -7 +7 -8 +8 -9 +9 -10 +10 -11 Result is like: 200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51 200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51 200707,9580,58,7,2,1,PRI,1,1,138,204173,0,5,10,-58.51,-58.51 200707,9580,58,7,2,1,SEC,1,1,138,204173,0,5,10,-58.51,58.51 200707,9580,58,7,2,1,PRI,1,1,139,170842,0,5,10,-25.98,-25.98 200707,9580,58,7,2,1,SEC,1,1,139,170842,0,5,10,-25.98,25.98 If you check the data, sort is screwed up, 3rd row should come before second and PRI is lesser than SEC. But when i sort the same data using the below command sort -t',' +0 -1n +1 -2n +2 -3n +3 -4n +4 -5n +5 -6n +6 -7 +7 -8n +8 -9n +9 -10n I made each field numeric specfic and PRI, SEC field left as Ascii I got the below result which the right one 200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51 200707,9580,58,7,2,1,PRI,1,1,138,204173,0,5,10,-58.51,-58.51 200707,9580,58,7,2,1,PRI,1,1,139,170842,0,5,10,-25.98,-25.98 200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51 200707,9580,58,7,2,1,SEC,1,1,138,204173,0,5,10,-58.51,58.51 200707,9580,58,7,2,1,SEC,1,1,139,170842,0,5,10,-25.98,25.98 When i am sorting either numeric or ascii, why the PRI, SEC is making a difference? |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|