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 executions = 135377 Total execution time (sec.ms) = 48.261439
Number of executions = 12 Total execution time (sec.ms) = 0.002608
Number of executions = 19513 Total execution time (sec.ms) = 1.529943
Number of executions = 25 Total execution time (sec.ms) = 0.008077
Number of executions = 50 Total execution time (sec.ms) = 0.029857
Number of executions = 4687 Total execution time (sec.ms) = 21.882761
Number of executions = 1 Total execution time (sec.ms) = 0.000086
Number of executions = 4 Total execution time (sec.ms) = 0.013008
Number of executions = 1 Total execution time (sec.ms) = 0.000226
Number of executions = 4699 Total execution time (sec.ms) = 0.791963
Number of executions = 1882 Total execution time (sec.ms) = 67.959492
Number of executions = 8 Total execution time (sec.ms) = 0.001410
Number of executions = 56232 Total execution time (sec.ms) = 235.199587
Number of executions = 3 Total execution time (sec.ms) = 1.742182
Number of executions = 23 Total execution time (sec.ms) = 0.003838
Number of executions = 9 Total execution time (sec.ms) = 0.000823
Number of executions = 8 Total execution time (sec.ms) = 0.032746
Number of executions = 24 Total execution time (sec.ms) = 0.040414
Number of executions = 134 Total execution time (sec.ms) = 1.165544
Number of executions = 14 Total execution time (sec.ms) = 0.004109
Number of executions = 1073 Total execution time (sec.ms) = 25.021018
Number of executions = 27838 Total execution time (sec.ms) = 189.024780
Number of executions = 402 Total execution time (sec.ms) = 2.425244
Number of executions = 11 Total execution time (sec.ms) = 0.146693
Number of executions = 30 Total execution time (sec.ms) = 0.105290
Number of executions = 28841 Total execution time (sec.ms) = 123.654048
Number of executions = 242 Total execution time (sec.ms) = 0.048610
Number of executions = 25 Total execution time (sec.ms) = 0.044363
.
.
<many more entries in file>

I used to divide the number and then sort the result....
But it seems "sort"ing is not working properly....

cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3 > tot_time_div_num_exec

Now looking at...."tot_time_div_num_exec" file

9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
41.095447/2 = 20.548 <----why we have greater number here?
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
47.139053/3 = 15.713
.
.

Please suggest me modification in my command and also tell me why sorting is not working?

NOTE: I have attached the input file 12.txt with this thread.
If anyone want to have look over it.

try:
sort -r -k3,3n

sort -r -k3,3n

  • doesn't work either....
    rather gives wrong result....
    check below....

cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3 | more
9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
41.095447/2 = 20.548 <----- not sorted
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
47.139053/3 = 15.713
7.567567/4 = 1.892
1845.985563/1083 = 1.705
5.069130/3 = 1.690

cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3,3n | more
9.742084/395690 = 0.000
9.510659/75186 = 0.000
9.194549/39095 = 0.000
8.146552/39095 = 0.000
8.008833/16050 = 0.000
735.600018/1760004 = 0.000
7.364725/28144 = 0.000
65.096662/842315 = 0.000
6.923107/37595 = 0.000
6.922309/127260 = 0.000
6.210832/27525 = 0.000
6.061399/82765 = 0.000
53.091542/833311 = 0.000
5.345867/53453 = 0.000
5.098626/49097 = 0.000
48.261439/135377 = 0.000
46.527917/791108 = 0.000
4.794862/9664 = 0.000
4.644286/65200 = 0.000
4.552522/11571 = 0.000
4.508161/57871 = 0.000
4.039346/87768 = 0.000
4.023613/48196 = 0.000

There are two problems with the code,

1- as Perderabo pointed out you need a numerical sort,
2- you need to decide how many significant integers you need after the decimal point. This will be decisive for your output, see below:

awk  '{printf "%s/%s = %3.6f\n", $11, $5, $11/$5}' file | sort -r -k3n | more

9.742084/395690 = 0.000025
0.000090/3 = 0.000030
0.000210/6 = 0.000035
1.123312/30534 = 0.000037
0.000075/2 = 0.000037
0.000074/2 = 0.000037
0.000943/25 = 0.000038
0.002482/60 = 0.000041

awk  '{printf "%s/%s = %3.3f\n", $11, $5, $11/$5}'  file | sort -r -k3n | more

9.742084/395690 = 0.000
9.510659/75186 = 0.000
9.194549/39095 = 0.000
8.146552/39095 = 0.000
8.008833/16050 = 0.000
735.600018/1760004 = 0.000

Otherwise the code works fine ( tested ).

As I look at the post, I see that you changed the data when you tried my sort suggestion. The new data that you used resulted in a a bunch of zeros. But help me out. Which one of those identical zeros do you think is out of order? :stuck_out_tongue:

Hello rubionis and Perderabo,
I appreciate your help.
But, Still I am not getting the desired output.

@Perderabo - I didn't change my input file after you gave me script.
@rubionis - the code you pasted doesn't give the output as Im expecting (plz chk my 1st post)

Please look at my first post.
In that I'm getting the correct result (of division) but problem is with sorting. I'm expecting the same result as I mentioned in my 1st post but sorting not wokring out :frowning:

I expect below output.....BLUE color... but in SORTED way.....
cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3 | more
9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
41.095447/2 = 20.548 <----- not sorted
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
47.139053/3 = 15.713
7.567567/4 = 1.892
1845.985563/1083 = 1.705
5.069130/3 = 1.690
.
.

Please use my input file which I sent before and do let me know the correct script....

Waiting for response....

yes you did.

Look at the output you posted before and after the time you tried my suggestion. Your largest divisor is 1083 and most divisors are just 1, 2, or 3. But when you tried my sort suggestion you suddenly have stuff like:
9.742084/395690
All a sort can do is re-arrange the order in which the lines are printed. The smallest divisor you used which my suggestion is much larger than the largest divisor you used before and after. Well, that your prerogative I guess... use any data you want. But you didn't answer my question. Regardless of the data, when you used my suggestion, the output you got was sorted correctly by field three. Why do you claim otherwise?

Perderabo,
I haven't changed any input.
Why I should do that? Rather I know you guys r helpful why I should delay my desired task ?

Also, as I said I have already uploaded the test input file....why dont you test the below 2 commands and see the difference by yourself?
I again run these 2 commands and still the same.....

Please use my test input and try at your end.....If your saying I changed the file :stuck_out_tongue: ......you should see the difference by urself.....

And yeah, I completely agree with your statement...the divisors are getting different....but why? again thats my question to you expert guys....

cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3 | more
9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
41.095447/2 = 20.548
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
47.139053/3 = 15.713
7.567567/4 = 1.892
1845.985563/1083 = 1.705
5.069130/3 = 1.690
.

cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3,3n | more
9.742084/395690 = 0.000
9.510659/75186 = 0.000
9.194549/39095 = 0.000
8.146552/39095 = 0.000
8.008833/16050 = 0.000
735.600018/1760004 = 0.000
7.364725/28144 = 0.000
65.096662/842315 = 0.000
6.923107/37595 = 0.000
6.922309/127260 = 0.000
6.210832/27525 = 0.000
6.061399/82765 = 0.000
53.091542/833311 = 0.000
5.345867/53453 = 0.000
5.098626/49097 = 0.000
48.261439/135377 = 0.000
46.527917/791108 = 0.000
4.794862/9664 = 0.000
4.644286/65200 = 0.000
4.552522/11571 = 0.000
4.508161/57871 = 0.000
4.039346/87768 = 0.000
4.023613/48196 = 0.000

.

Hello Perderabo OR anyone else...can you help to fix this ?

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 executions = 135377 Total execution time (sec.ms) = 48.261439
Number of executions = 12 Total execution time (sec.ms) = 0.002608
Number of executions = 19513 Total execution time (sec.ms) = 1.529943
Number of executions = 25 Total execution time (sec.ms) = 0.008077
Number of executions = 50 Total execution time (sec.ms) = 0.029857
Number of executions = 4687 Total execution time (sec.ms) = 21.882761
Number of executions = 1 Total execution time (sec.ms) = 0.000086
Number of executions = 4 Total execution time (sec.ms) = 0.013008
Number of executions = 1 Total execution time (sec.ms) = 0.000226
Number of executions = 4699 Total execution time (sec.ms) = 0.791963
Number of executions = 1882 Total execution time (sec.ms) = 67.959492
Number of executions = 8 Total execution time (sec.ms) = 0.001410
Number of executions = 56232 Total execution time (sec.ms) = 235.199587
Number of executions = 3 Total execution time (sec.ms) = 1.742182
Number of executions = 23 Total execution time (sec.ms) = 0.003838
Number of executions = 9 Total execution time (sec.ms) = 0.000823
Number of executions = 8 Total execution time (sec.ms) = 0.032746
Number of executions = 24 Total execution time (sec.ms) = 0.040414
Number of executions = 134 Total execution time (sec.ms) = 1.165544
Number of executions = 14 Total execution time (sec.ms) = 0.004109
Number of executions = 1073 Total execution time (sec.ms) = 25.021018
Number of executions = 27838 Total execution time (sec.ms) = 189.024780
Number of executions = 402 Total execution time (sec.ms) = 2.425244
Number of executions = 11 Total execution time (sec.ms) = 0.146693
Number of executions = 30 Total execution time (sec.ms) = 0.105290
Number of executions = 28841 Total execution time (sec.ms) = 123.654048
Number of executions = 242 Total execution time (sec.ms) = 0.048610
Number of executions = 25 Total execution time (sec.ms) = 0.044363
.
.
<many more entries in file>

I used to divide the number and then sort the result....
But it seems "sort"ing is not working properly....

cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -r -k3 > tot_time_div_num_exec

Now looking at...."tot_time_div_num_exec" file

9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
41.095447/2 = 20.548 <----why we have greater number here?
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
47.139053/3 = 15.713
.
.

Please suggest me modification in my command and also tell me why sorting is not working?

Now sure if we can, but....

Given a sample 12.txt file from the first post:

Number of executions = 2 Total execution time (sec.ms) = 0.009883
Number of executions = 8 Total execution time (sec.ms) = 0.001270
Number of executions = 135377 Total execution time (sec.ms) = 48.261439
Number of executions = 12 Total execution time (sec.ms) = 0.002608
Number of executions = 19513 Total execution time (sec.ms) = 1.529943
Number of executions = 25 Total execution time (sec.ms) = 0.008077
Number of executions = 50 Total execution time (sec.ms) = 0.029857
Number of executions = 4687 Total execution time (sec.ms) = 21.882761
Number of executions = 1 Total execution time (sec.ms) = 0.000086
Number of executions = 4 Total execution time (sec.ms) = 0.013008
Number of executions = 1 Total execution time (sec.ms) = 0.000226
Number of executions = 4699 Total execution time (sec.ms) = 0.791963
Number of executions = 1882 Total execution time (sec.ms) = 67.959492
Number of executions = 8 Total execution time (sec.ms) = 0.001410
Number of executions = 56232 Total execution time (sec.ms) = 235.199587
Number of executions = 3 Total execution time (sec.ms) = 1.742182
Number of executions = 23 Total execution time (sec.ms) = 0.003838
Number of executions = 9 Total execution time (sec.ms) = 0.000823
Number of executions = 8 Total execution time (sec.ms) = 0.032746
Number of executions = 24 Total execution time (sec.ms) = 0.040414
Number of executions = 134 Total execution time (sec.ms) = 1.165544
Number of executions = 14 Total execution time (sec.ms) = 0.004109
Number of executions = 1073 Total execution time (sec.ms) = 25.021018
Number of executions = 27838 Total execution time (sec.ms) = 189.024780
Number of executions = 402 Total execution time (sec.ms) = 2.425244
Number of executions = 11 Total execution time (sec.ms) = 0.146693
Number of executions = 30 Total execution time (sec.ms) = 0.105290
Number of executions = 28841 Total execution time (sec.ms) = 123.654048
Number of executions = 242 Total execution time (sec.ms) = 0.048610
Number of executions = 25 Total execution time (sec.ms) = 0.044363

and running:

awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' 12.txt| sort -r -k3,3n

we get:

48.261439/135377 = 0.000
1.529943/19513 = 0.000
0.791963/4699 = 0.000
0.048610/242 = 0.000
0.008077/25 = 0.000
0.004109/14 = 0.000
0.003838/23 = 0.000
0.002608/12 = 0.000
0.001410/8 = 0.000
0.001270/8 = 0.000
0.000823/9 = 0.000
0.000226/1 = 0.000
0.000086/1 = 0.000
0.029857/50 = 0.001
0.044363/25 = 0.002
0.040414/24 = 0.002
0.013008/4 = 0.003
235.199587/56232 = 0.004
123.654048/28841 = 0.004
0.105290/30 = 0.004
0.032746/8 = 0.004
21.882761/4687 = 0.005
0.009883/2 = 0.005
2.425244/402 = 0.006
189.024780/27838 = 0.007
1.165544/134 = 0.009
0.146693/11 = 0.013
25.021018/1073 = 0.023
67.959492/1882 = 0.036
1.742182/3 = 0.581

looks kosher to me......
I've just tested with the attached 12.txt from post #1 - it all looks good.
What OS are you under?

Please don't double post - it's against the rules.

Threads merged.

Firstly, sorry for reposting but the folks who were responding to earlier thread were not understanding the problem at all and were just claming I changed the input file...this is ridiculous !! Thats why I moved to new1.....

Anyways...It looks like "vgersh99" you have understood my problem :slight_smile:
Here is my oslevel...

>oslevel -s
5300-07-01-0748

Looking forward to hear from you soon...

Actually no - I'm in the same boat with everybody else (if you re-read my previous post): the sample file provided in the first post (and the attached file from the same post) when ran through the suggested awk script seem to return the correct data - RE-read my previous post with the quote data sample.

And no, I don't understand the 'oslevel': run 'uname -a' and post the output.
Good luck.

uname -a
AIX panipuri 3 5 00C5EFD04C00

I tried on diff machine...but same behavior :frowning:

$ uname -a
Linux matrix05 2.6.5-7.283-smp #1 SMP Wed Nov 29 16:55:53 UTC 2006 x86_64 x86_64 x86_64 GNU/Linux

I am with Perderabo and others...cannot figure out where you are getting those numbers for the execution times just doesn't make any sense. I ran the awk command on the sample input file you provided on AIX and the output was correct.

Did you get the (correct ) output in "SORTED" format ??
Like....
41.095447/2 = 20.548 <---- correct sort
47.139053/3 = 15.713 <---- correct sort
9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
7.567567/4 = 1.892
1845.985563/1083 = 1.705
5.069130/3 = 1.690
.
Why don't you paste the command and exact output you get?

The input...

Number of executions = 2 Total execution time (sec.ms) = 0.009883
Number of executions = 8 Total execution time (sec.ms) = 0.001270
Number of executions = 135377 Total execution time (sec.ms) = 48.261439
Number of executions = 12 Total execution time (sec.ms) = 0.002608
Number of executions = 19513 Total execution time (sec.ms) = 1.529943
Number of executions = 25 Total execution time (sec.ms) = 0.008077
Number of executions = 50 Total execution time (sec.ms) = 0.029857
Number of executions = 4687 Total execution time (sec.ms) = 21.882761
Number of executions = 1 Total execution time (sec.ms) = 0.000086
Number of executions = 4 Total execution time (sec.ms) = 0.013008
Number of executions = 1 Total execution time (sec.ms) = 0.000226
Number of executions = 4699 Total execution time (sec.ms) = 0.791963
Number of executions = 1882 Total execution time (sec.ms) = 67.959492
Number of executions = 8 Total execution time (sec.ms) = 0.001410
Number of executions = 56232 Total execution time (sec.ms) = 235.199587
Number of executions = 3 Total execution time (sec.ms) = 1.742182
Number of executions = 23 Total execution time (sec.ms) = 0.003838
Number of executions = 9 Total execution time (sec.ms) = 0.000823
Number of executions = 8 Total execution time (sec.ms) = 0.032746
Number of executions = 24 Total execution time (sec.ms) = 0.040414
Number of executions = 134 Total execution time (sec.ms) = 1.165544
Number of executions = 14 Total execution time (sec.ms) = 0.004109
Number of executions = 1073 Total execution time (sec.ms) = 25.021018
Number of executions = 27838 Total execution time (sec.ms) = 189.024780
Number of executions = 402 Total execution time (sec.ms) = 2.425244
Number of executions = 11 Total execution time (sec.ms) = 0.146693
Number of executions = 30 Total execution time (sec.ms) = 0.105290
Number of executions = 28841 Total execution time (sec.ms) = 123.654048
Number of executions = 242 Total execution time (sec.ms) = 0.048610
Number of executions = 25 Total execution time (sec.ms) = 0.044363

And the command and its output...

cat file | awk '{printf "%s/%s = %f\n", $11, $5,$11/$5}' | sort -r -k3
1.742182/3 = 0.580727
67.959492/1882 = 0.036110
25.021018/1073 = 0.023319
0.146693/11 = 0.013336
1.165544/134 = 0.008698
189.024780/27838 = 0.006790
2.425244/402 = 0.006033
0.009883/2 = 0.004941
21.882761/4687 = 0.004669
123.654048/28841 = 0.004287
235.199587/56232 = 0.004183
0.032746/8 = 0.004093
0.105290/30 = 0.003510
0.013008/4 = 0.003252
0.044363/25 = 0.001775
0.040414/24 = 0.001684
0.029857/50 = 0.000597
48.261439/135377 = 0.000356
0.008077/25 = 0.000323
0.004109/14 = 0.000293
0.000226/1 = 0.000226
0.002608/12 = 0.000217
0.048610/242 = 0.000201
0.001410/8 = 0.000176
0.791963/4699 = 0.000169
0.003838/23 = 0.000167
0.001270/8 = 0.000159
0.000823/9 = 0.000091
0.000086/1 = 0.000086
1.529943/19513 = 0.000078

"shamrock" your getting correct result BECAUSE your using only first 30 lines from 12.txt (the file which I use as input)....

Actual 12.txt has 3052 lines....

I suggest you to run the same command which you pasted above
"cat file | awk '{printf "%s/%s = %f\n", $11, $5,$11/$5}' | sort -r -k3"

againt my input file 12.txt....you will see the incorrect output (non-sorted one) which I have pasted many times in this thread....I dont think you guys are getting my point....

Plz concentrate - use my complete 12.txt as input file....you will see non sorted result....as

9.396545/1 = 9.397
9.039183/1 = 9.039
76.712522/10 = 7.671
6.857941/1 = 6.858
18.470404/3 = 6.157
4.516811/1 = 4.517
4.214784/1 = 4.215
4.043929/1 = 4.044
3.868609/1 = 3.869
3.442802/1 = 3.443
3.198656/1 = 3.199
41.095447/2 = 20.548 <----why we have greater number here?
2.967361/1 = 2.967
11.660539/4 = 2.915
2.599642/1 = 2.600
7.414902/3 = 2.472
2.375463/1 = 2.375
4.402904/2 = 2.201
2.123307/1 = 2.123
47.139053/3 = 15.713 <----why we have greater number here?
.
.