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....
# 22  
Old 03-16-2009
@Rahul,

I tried the below command in my AIX for your input file 12.txt (with 3052 records).

Code:
cat 12.txt | awk '{ printf "%s/%s = %3.3f\n", $11, $5, $11/$5}' | sort -k3,3nr | head -20

This gives the top 20 sorted output. The output was as below, which seems to be correct.

Code:
41.095447/2 = 20.548
47.139053/3 = 15.713
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

# 23  
Old 03-16-2009
Sort and Awk

Use this command.

I hope u vil get the proper output.

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

Thank you.
# 24  
Old 03-16-2009
Quote:
Originally Posted by uniesh
Use this command.

I hope u vil get the proper output.

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

Thank you.
That won't sort correctly because by itself "-r" stands for the entire record instead of the 3rd field only when specified as -k3,3r.
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