The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
sendmail with an embedded image bubba77 UNIX for Dummies Questions & Answers 0 03-10-2008 03:22 PM
How to add user on Embedded System siegfried UNIX for Advanced & Expert Users 1 01-06-2007 11:54 PM
Embedded SQL in AWK script 2nilotpal Shell Programming and Scripting 2 04-21-2004 05:33 PM
Embedded list? Is this possible zasxes Shell Programming and Scripting 1 09-22-2003 03:37 PM
Embedded programming TioTony High Level Programming 3 11-05-2002 09:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2008
mycrew2008 mycrew2008 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Trouble sorting numbers embedded

Hi All,

First time poster.

I have a text file that as many entries like below (single line):
egrep RspTime conlb.txt |more
S(xxx.xxx.xxx.xxx:5050:UP) Hits(13358983, 2/sec, P[12685309, 2/sec]) ATr(2) Mbps(0.07) BWlmt(0 kbits) RspTime(16.50 ms)
...
I am trying to sort on the RspTime from highest to lowest order. When I apply the following command I get a sort where the number start with 9:

suse10x:~ # egrep RspTime conlb.txt | awk '{print $10 $11 " " $1}' | sort -nr |more
RspTime(999.65ms) S(xxx.xxx.xxx.xxx:UP)
RspTime(99.95ms) S(yyy.yyy.yyy.yyy:80:UP)
...<snip>
RspTime(9371.11ms) S(xxx.xxx.xxx.xxx:UP)
RspTime(9345.20ms) S(yyy.yyy.yyy.yyy:80:UP)
RspTime(9319.48ms) S(yyy.yyy.yyy.yyy:80:UP)

There are response times that are much higher than 999.65.

How can I sort this to get the output I am looking for with the highest RspTime ?
  #2 (permalink)  
Old 04-04-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 753
Question Post sample of input data

That's because your command is not able to isolate the RspTime numbers from the non-numbers. Formulate your command so that you sort only on the numerical RspTime column instead of the alphanumeric data. Show a sample of the input data file also.
  #3 (permalink)  
Old 04-04-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,130

Code:
nawk -F'[( ]' '{print $(NF-1) "\t" $0}' conlb.txt  | sort -rn -k1,1 | cut -f2-


Last edited by vgersh99; 04-04-2008 at 11:55 AM.. Reason: reverse order
  #4 (permalink)  
Old 04-04-2008
mycrew2008 mycrew2008 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
Awsome Works like a champ!

Quote:
Originally Posted by vgersh99 View Post
Code:
nawk -F'[( ]' '{print $(NF-1) "\t" $0}' conlb.txt  | sort -rn -k1,1 | cut -f2-
Hey vgersh99.

This is fantastic. One question though that i can not figure out. what is the "\t" doing special? If I replace it with a space " " I get the (NF-1) first in the print out but the "\t" is keeping it in the orginal location.

Thanks again!
  #5 (permalink)  
Old 04-04-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,130
"\t" (tab) is a default field separator for 'cut' that I use in the last piped command.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0