checking the smallest and largest number | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

checking the smallest and largest number

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 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 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 04-24-2008
Franklin52's Avatar
Franklin52 Franklin52 is offline Forum Staff  
Moderator
 
Join Date: Feb 2007
Last Activity: 20 December 2014, 8:12 AM EST
Location: The Netherlands
Posts: 7,720
Thanks: 126
Thanked 538 Times in 508 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 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 05:53 AM.. Reason: adding code tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 04:33 AM
Help with find highest and smallest number in a file with c cpp_beginner Programming 2 07-24-2011 11:30 PM
AWK (how) to get smallest/largest nr of ls -la abciscool Shell Programming and Scripting 5 04-12-2010 07:24 AM
How to print largest and smallest number. amp10388 UNIX for Dummies Questions & Answers 2 05-07-2008 11:28 AM
search the largest number and duplicates string fongthai Shell Programming and Scripting 13 05-18-2007 11:40 AM



All times are GMT -4. The time now is 07:52 PM.