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

awk '{if($NF ~ "ms" ){ sub("Request---","", $NF ); sub("ms",""); print $NF}}' patterns | sort -n

Best Regards,
Rakesh UV

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?

Try this:

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

hi

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