Sponsored Content
Top Forums Shell Programming and Scripting Average, min and max in file with header, using awk Post 302771304 by RudiC on Wednesday 20th of February 2013 08:42:12 AM
Old 02-20-2013
Well, you're on the right track, just need to get your ducks in a row. Look at this an adapt to your needs:
Code:
awk     'NR==1  {max=0;min=1}
         NR>1   {sum+=$6
                 if (min>$6) min=$6
                 if (max<$6) max=$6
                 cnt = NR
                }
         END    {print  sum/(cnt-1), min, max}
        ' file
0.0113093 0.003118 0.01961

Some further reading on awk might be really helpful.
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Awk search for max and min field values

hi, i have an awk script and I managed to figure out how to search the max value but Im having difficulty in searching for the min field value. BEGIN {FS=","; max=0} NF == 7 {if (max < $6) max = $6;} END { print man, min} where $6 is the column of a field separated by a comma (3 Replies)
Discussion started by: Kirichiko
3 Replies

2. Shell Programming and Scripting

get min, max and average value

hi! i have a file like the attachement. I'd like to get for each line the min, max and average values. (there is 255 values for each line) how can i get that ? i try this, is it right? BEGIN {FS = ","; OFS = ";";max=0;min=0;moy=0;total=0;freq=890} $0 !~ /Trace1:/ { ... (1 Reply)
Discussion started by: riderman
1 Replies

3. Shell Programming and Scripting

Count time min/max/average for ping

I am redirecting my ping output to a file. The sample output is like this: 64 bytes from xx.xx.xx.167: icmp_seq=4490 ttl=116 3.75 ms 2011Jul12- 15 40 16 64 bytes from xx.xx.xx.167: icmp_seq=4491 ttl=116 5.29 ms 2011Jul12- 15 40 17 64 bytes from xx.xx.xx.167: icmp_seq=4492 ttl=116 4.88 ms... (6 Replies)
Discussion started by: zorrox
6 Replies

4. Shell Programming and Scripting

Find min.max value if matching columns found using AWK

Input_ File : 2 3 4 5 1 1 0 1 2 1 -1 1 2 1 3 1 3 1 4 1 6 5 6 6 6 6 6 7 6 7 6 8 5 8 6 7 Desired output : 2 3 4 5 -1 1 4 1 6 5 6 8 5 8 6 7 (3 Replies)
Discussion started by: vasanth.vadalur
3 Replies

5. Shell Programming and Scripting

How to find the average,min,max ,total count?

Hi , Below is my sample data,I have this 8 column(A,B,C,D,E,F,G,H) in csv file. A , B ,C ,D ,E ,F,G ,H 4141,127337,24,15,20,69,72.0,-3 4141,128864,24,15,20,65,66.0,-1 4141,910053,24,15,4,4,5.0,-1 4141,910383,24,15,22,3,4.0,-1 4141,496969,24,15,14,6,-24.0,-18... (7 Replies)
Discussion started by: vinothsekark
7 Replies

6. Shell Programming and Scripting

Number of elements, average value, min & max from a list of numbers using awk

Hi all, I have a list of numbers. I need an awk command to find out the numbers of elements (number of numbers, sort to speak), the average value the min and max value. Reading the list only once, with awk. Any ideas? Thanks! (5 Replies)
Discussion started by: black_fender
5 Replies

7. Shell Programming and Scripting

Get the min avg and max with awk

aaa: 3 ms aaa: 2 ms aaa: 5 ms aaa: 10 ms .......... to get the 3 2 5 10 ...'s min avg and max something like min: 2 ms avg: 5 ms max: 10 ms (2 Replies)
Discussion started by: yanglei_fage
2 Replies

8. Shell Programming and Scripting

awk script to find min and max value

I need to find the max/min of columns 1 and 2 of a 2 column file what contains the special character ">". I know that this will find the max value of column 1. awk 'BEGIN {max = 0} {if ($1>max) max=$1} END {print max}' input.file But what if I needed to ignore special characters in the... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

9. Shell Programming and Scripting

How to get min and max values using awk?

Hi, I need your kind help to get min and max values from file based on value in $5 . File1 SP12.3 stc 2240806 2240808 + ID1_N003 ID2_N003T0 SP12.3 sto 2241682 2241684 + ID1_N003 ID2_N003T0 SP12.3 XE 2239943 2240011 + ID1_N003 ID2_N003T0 SP12.3 XE 2240077 2241254 + ID1_N003 ... (12 Replies)
Discussion started by: redse171
12 Replies

10. Shell Programming and Scripting

awk Sort 2d histogram output from min(X,Y) to max(X,Y)

I've got Gnuplot-format 2D histogram data output which looks as follows. 6.5 -1.25 10.2804 6.5404 -1.25 10.4907 6.58081 -1.25 10.8087 6.62121 -1.25 10.4686 6.66162 -1.25 10.506 6.70202 -1.25 10.3084 6.74242 -1.25 9.68256 6.78283 -1.25 9.41229 6.82323 -1.25 9.43078 6.86364 -1.25 9.62408... (1 Reply)
Discussion started by: chrisjorg
1 Replies
VecStat(3pm)						User Contributed Perl Documentation					      VecStat(3pm)

NAME
Math::VecStat - Some basic numeric stats on vectors SYNOPSIS
use Math::VecStat qw(max min maxabs minabs sum average); $max=max(@vector); $max=max(@vector); ($max,$imax)=max(@vector); ($max,$imax)=max(@vector); $min=min(@vector); $min=min(@vector); ($max,$imin)=min(@vector); ($max,$imin)=min(@vector); $max=maxabs(@vector); $max=maxabs(@vector); ($max,$imax)=maxabs(@vector); ($max,$imax)=maxabs(@vector); $min=minabs(@vector); $min=minabs(@vector); ($max,$imin)=minabs(@vector); ($max,$imin)=minabs(@vector); $sum=sum($v1,$v2,...); $sum=sum(@vector); $sum=sum(@vector); $average=average($v1,$v2,...); $av=average(@vector); $av=average(@vector); $ref=vecprod($scalar,@vector); $ok=ordered(@vector); $ok=ordered(@vector); $ref=sumbyelement(@vector1,@vector2); $ref=diffbyelement(@vector1,@vector2); $ok=allequal(@vector1,@vector2); $ref=convolute(@vector1,@vector2); DESCRIPTION
This package provides some basic statistics on numerical vectors. All the subroutines can take a reference to the vector to be operated on. In some cases a copy of the vector is acceptable, but is not recommended for efficiency. max(@vector), max(@vector) return the maximum value of given values or vector. In an array context returns the value and the index in the array where it occurs. min(@vector), min(@vector) return the minimum value of given values or vector, In an array context returns the value and the index in the array where it occurs. maxabs(@vector), maxabs(@vector) return the maximum value of absolute of the given values or vector. In an array context returns the value and the index in the array where it occurs. minabs(@vector), minabs(@vector) return the minimum value of the absolute of the given values or vector. In an array context returns the value and the index in the array where it occurs. sum($v1,$v2,...), sum(@vector), sum(@vector) return the sum of the given values or vector average($v1,$v2,..), average(@vector), average(@vector) return the average of the given values or vector vecprod($a,$v1,$v2,..), vecprod($a,@vector), vecprod( $a, @vector ) return a vector built by multiplying the scalar $a by each element of the @vector. ordered($v1,$v2,..), ordered(@vector), ordered(@vector) return nonzero iff the vector is nondecreasing with respect to its index. To be used like if( ordered( $lowBound, $value, $highBound ) ){ instead of the (slightly) more clumsy if( ($lowBound <= $value) && ($value <= $highBound) ) { sumbyelement( @array1, @array2 ), diffbyelement(@array1,@array2) return the element-by-element sum or difference of two identically-sized vectors. Given $s = sumbyelement( [10,20,30], [1,2,3] ); $d = diffbyelement( [10,20,30], [1,2,3] ); $s will be "[11,22,33]", $d will be "[9,18,27]". allequal( @array1, @array2 ) returns true if and only if the two arrays are numerically identical. convolute( @array1, @array2 ) return a reference to an array containing the element-by-element product of the two input arrays. I.e., $r = convolute( [1,2,3], [-1,2,1] ); returns a reference to [-1,4,3] median evaluates the median, i.e. an element which separates the population in two halves. It returns a reference to a list whose first element is the median value and the second element is the index of the median element in the original vector. $a = Math::VecStat::median( [9,8,7,6,5,4,3,2,1] ); returns the list reference [ 5, 4 ] i.e. the median value is 5 and it is found at position 4 of the original array. If there are several elements of the array having the median value, e.g. [1,3,3,3,5]. In this case we choose always the first element in the original vector which is a median. In the example, we return [3,1]. =back =head1 HISTORY $Log: VecStat.pm,v $ Revision 1.9 2003/04/20 00:49:00 spinellia@acm.org Perl 5.8 broke test 36, exposing inconsistency in C<median>. Fixed, thanks to david@jamesgang.com. Revision 1.8 2001/01/26 11:10:00 spinellia@acm.org Added function median. Fixed test, thanks to Andreas Marcel Riechert <riechert@pobox.com> Revision 1.7 2000/10/24 15:28:00 spinellia@acm.org Added functions allequal diffbyelement Created a reasonable test suite. Revision 1.6 2000/06/29 16:06:37 spinellia@acm.org Added functions vecprod, convolute, sumbyelement Revision 1.5 1997/02/26 17:20:37 willijar Added line before pod header so pod2man installs man page correctly Revision 1.4 1996/02/20 07:53:10 willijar Added ability to return index in array contex to max and min functions. Added minabs and maxabs functions. Thanks to Mark Borges <mdb@cdc.noaa.gov> for these suggestions. Revision 1.3 1996/01/06 11:03:30 willijar Fixed stupid bug that crept into looping in min and max functions Revision 1.2 1995/12/26 09:56:38 willijar Oops - removed xy data functions. Revision 1.1 1995/12/26 09:39:07 willijar Initial revision BUGS
Let me know. I welcome any appropriate additions for this package. AUTHORS
John A.R. Williams <J.A.R.Williams@aston.ac.uk> Andrea Spinelli <spinellia@acm.org> perl v5.12.4 2011-07-11 VecStat(3pm)
All times are GMT -4. The time now is 12:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy