Getting average ,maximum and minimum value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting average ,maximum and minimum value
# 1  
Old 02-04-2013
Getting average ,maximum and minimum value

Hi Evreyone

below is the sample data i have in one file


Code:
Wed Jan 30  7	:04:50 2013	type1		419990050	101	ms
Wed Jan 30	 7	:04:58 2013	type1		488226363	101	ms
Wed Jan 30	 7	:05:03 2013	type1		431525334	101	ms
Wed Jan 30	 7	:05:48 2013	type2		400676615	101	ms
Wed Jan 30	 8	:09:46 2013	type3		414765261	101	ms
Wed Jan 30	 8	:10:03 2013	type4		408521082	101	ms
Wed Jan 30	 8	:19:02 2013	type3		418245756	101	ms
Wed Jan 30	 8	:19:07 2013	type2		413860792	101	ms
Wed Jan 30	 7	:21:11 2013	type2		421664181	101	ms
Wed Jan 30	 7	:21:45 2013	type3		448474303	101	ms
Wed Jan 30	 9	:21:56 2013	type1		431636405	101	ms
Wed Jan 30  9	:26:19 2013	type1		439923226	101	ms
Wed Jan 30	 9	:19:07 2013	type3		413860792	101	ms
Wed Jan 30	 7	:21:11 2013	type4		421664181	101	ms
Wed Jan 30	 7	:21:45 2013	type2		448474303	101	ms
Wed Jan 30	 7	:21:56 2013	type2		431636405	101	ms
Wed Jan 30  7	:26:19 2013	type3		439923226	101	ms


i have large amoount of data similar to above its response time for diffrent types of request (typ1,type2,type3,type4)on each day .

so from above what i require is
i if space is delimiter then

4 th filed is hours filed ,
so for each hour say from 7to8, 8to9 based for type 1 (7th field) what is count, max ,min and avg value,what is the in field 9 (ex value similarly for type2 ,type3,type4
# 2  
Old 02-04-2013
This seems like a lot of busy work when column 9 is always "101". The min, max, and avg will also always be 101.
# 3  
Old 02-04-2013
Hi Don Cragun,

this is just a sample data from file there may be other values on cloumn 9 than only 101
# 4  
Old 02-04-2013
Try something like:
Code:
# Variable dictionary:
#       c[k]    # of entries with key "k"
#       k       key: Day_of_week Month Day_of_month year hour_of_day type
#       kc      # of input lines with different keys
#       m[k]    minimum value for key "k"
#       M[k]    Maximum value for key "k"
#       o[x]    key to be printed on output line x (not counting header)
#       s[k]    sum of values for key "k"
awk '
# Set key and increment # of lines seen with this key.
c[k=($1" "$2" "$3" "$6"\t"$4"\t"$7)]++ == 0 {
        # This is first line with this key.
        m[k] = M[k] = s[k] = $9 # Initialize min, max, and sum for this key.
        o[++kc] = k             # Set the key to be printed on output line kc.
        next
}
{       # We have seen this key before:
        if($9 < m[k]) m[k] = $9 # Update minimum value for this key.
        if($9 > M[k]) M[k] = $9 # Update maximum value for this key.
        s[k] += $9              # Update sum for this key.
}
END {   # Print the keys with the corresponding count, minimum value, maximum
        # value, and calculate the average value in the order in which the key
        # first appeared in the input file(s).
        printf("---- Date ----\tHour\tType\tCount\t Min\t Max\t\tAvg\n")
        for(i = 1; i <= kc; i++)
                printf("%s\t%5d\t%4d\t%4d\t%11.3f\n",
                        o[i], c[o[i]], m[o[i]], M[o[i]], s[o[i]] / c[o[i]])
}' sample

As always, if you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk or nawk instead of awk.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create a list from minimum and maximum

Using the input file for each row , using columns 1 (min) and 2 (max) , and with increment of 4 each time I want to create the output file. Input file 1000 1012 2000 2001 2000 2008 3000 3001 Output desired 1000 2000 2001 1004 2000 2001 1008 2000 2001 1012 2000 2001 2000 3000 3001... (5 Replies)
Discussion started by: jiam912
5 Replies

2. Shell Programming and Scripting

awk to find maximum and minimum from column and store in other column

Need your support for below. Please help to get required output If column 5 is INV then only consider column1 and take out duplicates/identical rows/values from column1 and then put minimum value of column6 in column7 and put maximum value in column 8 and then need to do subtract values of... (7 Replies)
Discussion started by: as7951
7 Replies

3. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

4. Shell Programming and Scripting

Output minimum and maximum values for replicates ID

Hi All I hope that someone could help me! I have an input file like this, with 4 colum(ID, feature1, start, end): a x 1 5 b x 3 10 b x 4 9 b x 5 16 c x 5 9 c x 4 8 And my output file should be like this: a x 1 5 b x 3 16 c x 4 9 What I would like to do is to output for each ID... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

5. UNIX and Linux Applications

Maximum and minimum threshold in autosys

Good evening In a production system there are houndred of Jobs running and i´ve got to monitor all of them, but the problem arises when a job running takes much longer or conversely takes nothing and as operator is almost imposible to detect the máximum or mínimum threshold for a running job. Ive... (1 Reply)
Discussion started by: alexcol
1 Replies

6. Shell Programming and Scripting

Extract minimum/maximum using awk

From the below table I want to print highest value and lowest value using awk script. aaa 55 66 96 77 ggg 22 96 77 23 ddd 74 58 18 3 kkk 45 89 47 92 zzz 34 58 89 92 Thanks, Green edit by bakunin: it sure is not news to you that you should use CODE-tags, no? And that we do not want such... (3 Replies)
Discussion started by: gwgreen1
3 Replies

7. Shell Programming and Scripting

Finding minimum maximum and average

I am trying to find the minimum maximum and average from one file which has values Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from... (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

8. Shell Programming and Scripting

Print minimum and maximum values using awk

Can I print the minimum and maximum values of values in first 4 columns ? input 3038669 3038743 3037800 3038400 m101c 3218627 3218709 3217600 3219800 m290 ............. output 3037800 3038743 m101c 3217600 3219800 m290 (2 Replies)
Discussion started by: quincyjones
2 Replies

9. Shell Programming and Scripting

minimum and maximum from columns

Hi Friends, my input file is this way chr1 100 120 abc chr1 100 121 def chr1 100 122 ghi chr2 240 263 kil chr2 240 276 ghj chr2 255 290 hjh my output chr1 100 122 abc chr2 240 276 kil chr2 255 290 hjh Basically, I want to match on first and second column and then print the... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

10. Homework & Coursework Questions

Find the Maximum value and average of a column

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am trying to complete a script which will allow me to find: a) reads a value from the keyboard. (ask the... (4 Replies)
Discussion started by: dstewie
4 Replies
Login or Register to Ask a Question