Use awk to calculate the maximum, minimum, and average values
Source: Internet
Author: User
When you use awk to calculate the maximum value, minimum value, and average value to help colleagues solve the problem, you need to query the maximum value, minimum value, and average value of a specific value on the day from the log, and finally implement the following two methods: 1. sort By sort, calculate the maximum and minimum values, and use the for loop to calculate the average value: grepR... when you use awk to calculate the maximum value, minimum value, and average value to help colleagues solve the problem, you need to query the maximum value, minimum value, and average value of a specific value on the day from the log, and finally implement the following two methods: 1. use sort to sort, calculate the maximum and minimum values, and use the for loop to calculate the average value: grep RenewalCheckIbatisDAO. * getHistoryPolicyListByLicenceNo pafa. log | awk-F 'time = ''{print $2} '| awk-F 'Ms' {a [NR] = $1} END {B = 0; c = a [1]; d = a [1]; for (I in a) {B = B + a [I]; if (c> a [I]) c = a [I]; if (d 2. use for loop + if to determine the maximum value, minimum value, and average value: grep RenewalCheckIbatisDAO. * getHistoryPolicyListByLicenceNo pafa. log.2013-05-19 | awk-F 'time = ''{print $2} '| awk-F 'Ms' {a [NR] = $1} END {B = 0; c = a [1]; d = a [1]; for (I in a) {B = B + a [I]; if (c> a [I]) c = a [I]; if (d tested in logs, the efficiency of the two is similar: [pub_log_mon @ cnsz031500 pa18shopauto] $ wc-l pafa. log.2013-05-195038206 pafa. log.2013-05-19 [pub_log_mon @ cnsz031500 pa18shopauto] $ time (grep RenewalCheckIbatisDAO. * getHistoryPolicyListByLicenceNo pafa. log.2013-05-19 | awk-F 'time = ''{print $2} '| awk-F 'Ms' {print $1 |" sort-n "}' | awk '{a [NR] = $1} END {for (I in) B = B + a [I]; print "Min:" a [1], "Max:" a [NR], "Avg:" B/NR} ') Min: 0 Max: 1029 Avg: 45.0941 real 0m2. 450 suser 0m0. 893 ssys 0m1. 613 s [pub_log_mon @ cnsz031500 pa18shopauto] $ time (grep RenewalCheckIbatisDAO. * getHistoryPolicyListByLicenceNo pafa. log.2013-05-19 | awk-F 'time = ''{print $2} '| awk-F 'Ms' {a [NR] = $1} END {B = 0; c = a [1]; d = a [1]; for (I in a) {B = B + a [I]; if (c> a [I]) c = a [I]; if (dMin: 0 Max: 1029 Avg: 45.0941 real 0m2. 432 suser 0m0. 895 ssys 0m1. 571 s
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service