Why is sort not working properly here ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why is sort not working properly here ?
# 8  
Old 03-12-2013
Quote:
Originally Posted by DGPickett
Since DISK is a constant four, you want to key your sort on the first field character 5 and following, numeric ordering. In the the ol day, this was '-n +0.4 -0.99' but now it is -k1.5,1.99n, as field and character offsets in +- ar zero based and in -k, one based.

If you rename your volumes with leading zeros then there is no problem with simple sort.
Although the .99 will work for most fields, the standards say that -k1.5,1.99n specifies a sort key performing a numeric sort on the 5th through the 99th characters of the 1st field. The standard way to specify performing a numeric sort starting with the 5th character of the 1st field through the end of the 1st field would be -k1.5,1n or -k1.5,1.0n. And, for the record, the sort key -k1.5n specifies a numeric sort key starting with the 5th character of the 1st field and continuing through the end of the line.
# 9  
Old 03-12-2013
Yes, 99 was a hack for as many digits as sort can find. Since sort probably does an atof(), it stops when it hits non-numeric after white space and then numeric.

Remember that in not -n, sort deals with letters -- you could go hex or just 0-9A-Z on a digit. As long as $LC_ALL is C, sort is in ascii/iso8859-1 one byte char land where 0-9 are less than A-Z. I even came up with a special code where I fused the values of visual synonyms like 0 and O, S and 5, 1 and I, 2 and Z, 8 and B together for a 5 bit number, but now I am 1 short, so choose a font with a small top on the 8 (10 + 26 = 36, - 4 = 32). I was working on tape identity numbers, where the OS had 5 places but the customer had way over 100K volumes. 5 5 bit numbers is 32 billion. If you go lower case an symbols, you might make 6 bits, again eliminating the visually similar.

Last edited by DGPickett; 03-12-2013 at 12:57 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

How do I sort data in column properly?

Can i use 'column' command to get the required 3rd column output? Input example: 1 2 345678 90 2 2 356 42 3 3 8265 55 Output required: 1 2 345678 90 2 2 356 42 3 3 8265 55 Basically i want the 3rd column to be justified to the right, instead of left.... (3 Replies)
Discussion started by: nurul_nadzirah
3 Replies

2. Shell Programming and Scripting

Expansion not working properly

I'm using an Ubuntu machine and expansion is not working properly. What would cause this? Do I need to check for any particular bash packages? $ ipcs -m | grep $USER | awk '{printf "%s ",$2}' $ ipcs -m | grep UNF | awk '{printf "%s ",$2}' 294912 1048577 425986 688131 786436 1245189... (14 Replies)
Discussion started by: cokedude
14 Replies

3. Linux

rexec not working properly

Hi, I am trying to enable rexec to automate certain tasks(it has to be rexec, not ssh or any other due to the system environment), so after switching to linux, I followed the certain instructions that were laid out in the web. My operating system is fedora 17, so I first installed the... (1 Reply)
Discussion started by: wringer
1 Replies

4. Red Hat

sudo is not working properly

This is the first time for using sudo for me. # visudo ## Allows people in group admin to run all commands %admin ALL=(ALL) ALL # groupadd admin # useradd temp # usermod -a -G admin temp # id temp uid=506(temp) gid=506(temp) groups=506(temp),507(admin) # #sudo... (5 Replies)
Discussion started by: getrue
5 Replies

5. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies

6. UNIX for Advanced & Expert Users

Sendmail is not working properly

Hi All, Can any one help me to solve the issue. The Issue is, i have started the sendmail service on my RHEL 4 update 6 box, I am able to send the mail from my box to almost all of the Email Id's except few. Exampe, test mail. . Output is :the message is sent. now if I send the... (2 Replies)
Discussion started by: akhtar.bhat
2 Replies

7. Shell Programming and Scripting

\n not working properly

Hi all, I'm trying to generate a series of txt files starting from a plain csv file part of my code: #!/bin/ksh INSTALLDIR=/Users/ME/Installdir CSV=CSV.csv TMP=/tmp/$(basename $0).txt tr -s "\r" "\n" < /$INSTALLDIR/$CSV > $TMP function Makefiles { printf '%24s:%30s\n' "sometext"... (1 Reply)
Discussion started by: Jive Spector
1 Replies

8. Shell Programming and Scripting

Korn: How to zero fill df output so it will sort properly

I'm looking for a way in Korn shell to zero fill (or space fill) the output from df so that it will sort properly. "Raw" output from df -k: df -k Filesystem kbytes used avail capacity Mounted on /dev/vx/dsk/rootvol 4131866 3593302 497246 88% / /proc ... (9 Replies)
Discussion started by: shew01
9 Replies

9. Programming

y is this not working properly?

#include <stdio.h> #include <sys/types.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> struct stat s; main() { char c; if (fork()==0) { system("clear"); do { printf("myAI\\>§ "); scanf("%s",c); if(stat(c,&s)>-1) {... (3 Replies)
Discussion started by: C|[anti-trust]
3 Replies

10. UNIX for Dummies Questions & Answers

Keyboard not working properly...

Hello Again, Those that have noticed my earlier posts will know that I have succesfully installed Solaris 8 onto my pc. I haven't been able to get x-server working (i think it doesn't like my video card) though I've been able to log into root (with a bit of help from unix forums :o ) and have... (2 Replies)
Discussion started by: timresh
2 Replies
Login or Register to Ask a Question