从命令行获取一组数字的平均值的最快方法是什么?
使用您期望在 nix 系统上找到的任何工具(事实上,如果您愿意,msdos 也很好),计算一组数字的平均值的最简单/最快的方法是什么,假设您有一个流或文件中的每行?
Using any tools which you would expect to find on a nix system (in fact, if you want, msdos is also fine too), what is the easiest/fastest way to calculate the mean of a set of numbers, assuming you have them one per line in a stream or file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这会将总和累加到
n
中,然后除以项目数(NR
= 记录数)。适用于整数或实数。
This accumulates the sum in
n
, then divides by the number of items (NR
= Number of Records).Works for integers or reals.
awk
Awk
在 UNIX 上使用 Num-Utils:
Using Num-Utils for UNIX:
使用“st”(https://github.com/nferraz/st):
指定一个选项以查看个人统计数据:(
免责声明:我编写了这个工具:))
Using "st" (https://github.com/nferraz/st):
Specify an option to see individual stats:
(DISCLAIMER: I wrote this tool :))
在 Powershell 中,这将是
当然,这是详细的语法。 如果您使用别名输入,
In Powershell, it would be
Of course, that's the verbose syntax. If you typed it using aliases,
珀尔。
买者自负:我的语法可能有点古怪。
Perl.
Caveat Emptor: My syntax may be a little whiffly.
Ruby one liner
来源
Ruby one liner
source