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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not working..."sort" not working properly....
# 1  
Old 03-14-2009
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
.
# 2  
Old 03-14-2009
try:
sort -r -k3,3n
# 3  
Old 03-14-2009
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
# 4  
Old 03-14-2009
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:

Code:
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 ).
# 5  
Old 03-14-2009
Quote:
Originally Posted by Rahulpict
[B][COLOR=Blue]sort -r -k3,3n
- doesn't work either....
rather gives wrong result....
check below....
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? Smilie
# 6  
Old 03-14-2009
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 :-(

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....
# 7  
Old 03-14-2009
Quote:
Originally Posted by Rahulpict
@Perderabo - I didn't change my input file after you gave me script.
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

"SQLPLUS -S " is not working in one environment where same code is working in another

"SQLPLUS -S " is not working in one environment where same code is working in another getting below error =================================== SQL*Plus: Release 11.2.0.3.0 Production Copyright (c) 1982, 2011, Oracle. All rights reserved. Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus... (1 Reply)
Discussion started by: yogendra.barode
1 Replies

2. UNIX for Beginners Questions & Answers

Automate "touch" bash script not working.

#!/bin/bash -i SAVEIFS=$IFS IFS=$"\n\b" picc=$* if ; then echo $TDATE if ; then touch dummy touch -t "tdate" dummy touch -r "dummy" "$picc" else echo -e "No mod date value to apply. If there is one in your shell,\ninvoke \eStarted asking advice on this (on Linuxquestions.org).... (9 Replies)
Discussion started by: iamwrong
9 Replies

3. Shell Programming and Scripting

"if" Loop not working when executing script using cron

I am facing this weird issue where the script is working fine from the command line but when I am executing it from cron though it is working fine but the "if" loop is processing else part though I know that the if part of the logic is true and ideally the loop should execute the if portion. ... (3 Replies)
Discussion started by: sk2code
3 Replies

4. Shell Programming and Scripting

Why is sort not working properly here ?

Platform: RHEL 5.4 In the below text file I have strings like following. $ cat /tmp/mytextfile.txt DISK1 DISK10 DISK101 DISK102 DISK103 DISK104 DISK105 DISK106 DISK107 DISK108 DISK109 DISK110 DISK111 DISK112 DISK113 DISK114 (8 Replies)
Discussion started by: kraljic
8 Replies

5. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

6. Shell Programming and Scripting

Script that "should work" it's not working.

Hi, this is my script: #!/bin/bash trabajo=$1 numero=`jobs | grep -n $trabajo | cut -d':' -f1` echo $trabajo echo $numero kill %$numero wait For some reason, numero=`jobs | grep -n $trabajo | cut -d':' -f1` that line wont save in numero the number I am looking for BUT if I write it... (7 Replies)
Discussion started by: lamachejo
7 Replies

7. Shell Programming and Scripting

"Print" not working in script

Hello everybody, I've gotten a script together that is designed to open a .bin file and read it 32 bits at a time and then add it to the checksum. However, the only issue that I have is that it will not print anything at the end. Can anyone help me? Also, is the & symbol used for restraining... (2 Replies)
Discussion started by: TeamUSA
2 Replies

8. Shell Programming and Scripting

"sed" command is not working in shell script

Hi All, I am not much strong in shell scripting... I am using sed command in my script to find and replace a string....... This is how script looks : ############# #!/usr/bin/ksh CONFIG_FILE=iom_test.txt FIND=`echo "NIS_FTP_SERVER1=123.456.iom.com"` REPLACE=`echo... (2 Replies)
Discussion started by: askumarece
2 Replies

9. Shell Programming and Scripting

script not working after "tail -f"

Hi Everyone , I am facing a strange problem i have made the follwing script to watch a appending log file (abc.log) but its not moving after the line tail -f , any suggestions ===================================== #!/bin/bash while true do tail -f abc.log | grep "exceptions" echo hi... (12 Replies)
Discussion started by: xander
12 Replies

10. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies
Login or Register to Ask a Question