列中的最小值、平均值和最大值
我有下一个问题,我想要有两个最小值、一个最大值和此输入的平均值:
Call 1 1.160 ms
Call 2 0.163 ms
Call 3 1.154 ms
Call 4 1.029 ms
Call 5 0.291 ms
Call 6 1.186 ms
Call 7 1.089 ms
Call 8 1.122 ms
Call 9 0.975 ms
Call 10 1.224 ms
Call 11 0.965 ms
Call 12 1.047 ms
Call 13 1.138 ms
Call 14 1.217 ms
Call 15 1.189 ms
Call 16 1.115 ms
Call 17 0.950 ms
Call 18 1.112 ms
Call 19 1.227 ms
Call 20 1.071 ms
Call 21 1.108 ms
Call 22 1.191 ms
Call 23 1.139 ms
Call 24 1.032 ms
Call 25 1.305 ms
Call 26 1.085 ms
Call 27 1.404 ms
Call 28 1.282 ms
Call 29 1.031 ms
Call 30 1.018 ms
Call 31 1.308 ms
Call 32 1.299 ms
Call 33 1.096 ms
Call 34 1.129 ms
Call 35 1.271 ms
Call 36 1.035 ms
Call 37 1.238 ms
Call 38 1.150 ms
Call 39 1.042 ms
Call 40 0.948 ms
我一直在使用这些命令:
awk 'min=="" || $3 < min {min=$3; minline=$0}; END{ print minline}'
awk '{ if ($3>max) {max=$3; line=$0} } END {print line }'
awk '{s+=$3} END{print "Number of Calls: "NR, "\nAverage: "s/(NR)}'
输出是这样的:
Minimun: Call 18 0.212 ms
Maximun: Call 27 1.404 ms
Number of Calls: 40
Average: 1.1071
但我需要有 2 个最小值,其中之一它们如上所示,但另一个应该是大于 0.800 的任何数字。我尝试过这个:
awk 'min=="0.800" || $3 < min {min=$3; minline=$0}; END{ print minline}'
但它没有向我显示任何内容。拜托,我需要你的帮助才能将其放入脚本中。
预先感谢您的帮助
I have the next question, I'll like to have TWO minimun values, a maximun value and the average for this input:
Call 1 1.160 ms
Call 2 0.163 ms
Call 3 1.154 ms
Call 4 1.029 ms
Call 5 0.291 ms
Call 6 1.186 ms
Call 7 1.089 ms
Call 8 1.122 ms
Call 9 0.975 ms
Call 10 1.224 ms
Call 11 0.965 ms
Call 12 1.047 ms
Call 13 1.138 ms
Call 14 1.217 ms
Call 15 1.189 ms
Call 16 1.115 ms
Call 17 0.950 ms
Call 18 1.112 ms
Call 19 1.227 ms
Call 20 1.071 ms
Call 21 1.108 ms
Call 22 1.191 ms
Call 23 1.139 ms
Call 24 1.032 ms
Call 25 1.305 ms
Call 26 1.085 ms
Call 27 1.404 ms
Call 28 1.282 ms
Call 29 1.031 ms
Call 30 1.018 ms
Call 31 1.308 ms
Call 32 1.299 ms
Call 33 1.096 ms
Call 34 1.129 ms
Call 35 1.271 ms
Call 36 1.035 ms
Call 37 1.238 ms
Call 38 1.150 ms
Call 39 1.042 ms
Call 40 0.948 ms
I've been using those commands:
awk 'min=="" || $3 < min {min=$3; minline=$0}; END{ print minline}'
awk '{ if ($3>max) {max=$3; line=$0} } END {print line }'
awk '{s+=$3} END{print "Number of Calls: "NR, "\nAverage: "s/(NR)}'
The output is this:
Minimun: Call 18 0.212 ms
Maximun: Call 27 1.404 ms
Number of Calls: 40
Average: 1.1071
But I need to have 2 minimun values, one of them is showed above but the other one should be any number greather than 0.800. I've trying this:
awk 'min=="0.800" || $3 < min {min=$3; minline=$0}; END{ print minline}'
But it shows me nothing. Please, I need your help to place this in a script.
Thank you in advance for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
输出:
注意:对于“任何大于 0.800 的数字”,我只是检查了 Max,如果它 > 0.800,则将其打印为幻数。如果没有,则打印 None。
编辑
对OP评论的更改:
输出:
output:
Note: for the "any number greater than 0.800", i just checked the Max, if it >0.800,print it as the magic number. if not, print None.
EDIT
changes for OP's comment:
output:
您想要两个最小值:
输出:
您想要最小值和第二个最小值大于 0.8 毫秒:
输出:
You want the two minimal values:
output:
You want the minimal value and the second minimal value grater than 0.8 ms:
output:
解决方案 1
这是我在 Perl 中的解决方案,我是一个新手,但想学习:
唯一棘手的部分是计算 $min2,它是第二小的值。我的脚本看起来很长,但我相信它比其他一些解决方案更容易理解和维护。
方案2
该方案只计算两个min,一个max,但是比较短:
Solution 1
Here is my solution in Perl, in which I am a newbie, but would like to learn:
The only tricky part is to calculate $min2, which is the next-to-smallest value. My script seems long, but I believe it is easier to understand and maintain than some other solutions.
Solution 2
This solution only calculates the two min, one max, but it is relatively short: