Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

checking the smallest and largest number

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-24-2008
subin_bala subin_bala is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 7 April 2010, 1:18 PM EDT
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
checking the smallest and largest number

Hi All,

My script is reading a log file line by line
log file is like ;

19:40:22 :INFO Total time taken to Service External Request---115ms
19:40:25 DEBUG : Batch processed libdaemon.x86_64 0-0.10-5.el5 - u
19:40:22 INFO Total time taken to Service External Request---20ms
19:40:24 DEBUG : Adding libgtk-java - 2.8.7-3.el5.x86_64 in mode u
19:40:22 INFO : Total time taken to Service External Request---10ms


While reading i am catching numbers 115,20,10 from respective lines..
How can i check the smallest and largest numbers from this?

Thanks
Subin
Sponsored Links
    #2  
Old Unix and Linux 04-24-2008
uvrakesh uvrakesh is offline
Registered User
 
Join Date: Dec 2005
Last Activity: 2 January 2013, 9:10 AM EST
Posts: 82
Thanks: 0
Thanked 1 Time in 1 Post
awk '{if($NF ~ "ms" ){ sub("Request---","", $NF ); sub("ms",""); print $NF}}' patterns | sort -n

Best Regards,
Rakesh UV
Sponsored Links
    #3  
Old Unix and Linux 04-24-2008
subin_bala subin_bala is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 7 April 2010, 1:18 PM EDT
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Hi ,

Thanks for the reply. But its not working for me..

while read data
do
STR_TOTALTIME=`echo $data | egrep "*.Visited URL.*ms"`
COUNT_TOTALTIME=`echo $STR_TOTALTIME | awk '{print $NF}' | awk 'BEGIN {FS="-";}{print $4}'| awk 'BEGIN {FS="m";}{print $1}'`


By using this code i am getting the value 115,20 and 10 respectively in COUNT_TOTALTIME varable.How can i print the smallest and largest values in the log file?
    #4  
Old Unix and Linux 04-24-2008
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 28 May 2015, 3:15 PM EDT
Location: The Netherlands
Posts: 7,730
Thanks: 129
Thanked 544 Times in 512 Posts
Try this:


Code:
awk -F- '
/INFO/{v=int($NF)}
{if(NR==1){min=max=v;next}}
{if(max<v){max=v}if(min>v){min=v}}
END{print "Min: " min,"Max: "max}' file

Regards
Sponsored Links
    #5  
Old Unix and Linux 04-24-2008
penchal_boddu penchal_boddu is offline
Registered User
 
Join Date: Apr 2008
Last Activity: 11 February 2013, 3:10 PM EST
Location: Bangalore
Posts: 173
Thanks: 0
Thanked 5 Times in 4 Posts
hi

Code:
awk -F"-" '/INFO/{print $NF}' new | tr 'ms' '  ' | sort -n >> pp
echo "Largest time :: `tail -1 pp` "
echo "Smallest time :: `head -1 pp` "


Last edited by Franklin52; 06-23-2010 at 04:53 AM.. Reason: adding code tags
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Largest number in array. Help! Sundown Shell Programming and Scripting 5 03-22-2012 03:33 AM
Help with find highest and smallest number in a file with c cpp_beginner Programming 2 07-24-2011 10:30 PM
AWK (how) to get smallest/largest nr of ls -la abciscool Shell Programming and Scripting 5 04-12-2010 06:24 AM
How to print largest and smallest number. amp10388 UNIX for Dummies Questions & Answers 2 05-07-2008 10:28 AM
search the largest number and duplicates string fongthai Shell Programming and Scripting 13 05-18-2007 10:40 AM



All times are GMT -4. The time now is 12:20 AM.