linux: 如何对文本输入执行类似于 awk 的统计?

linux: how can I perform awk-like statistics on text input?

我有一些数据如下所示:

add 0.17411 0.00018 0.17430 0
add 0.03959 0.00014 0.03974 1
add 0.00923 0.00013 0.00935 2
add 0.01346 0.00011 0.01357 3
add 1.00567 0.00015 1.00582 4

如何计算这些数字的一些统计数据?我想获取每一列的最小值、最大值、平均值、标准差等信息。

理想情况下,它应该类似于 awk,并包含在标准 linux 发行版中。

prog max(column1),avg(column1) < myfile

你为什么不用数据库:

首先,将列名称添加到您的文件中:

sed -i 'i1col0 col1 col2 col3 col4' myfile

然后,创建一个数据库并输出一些统计信息:

sqlite3 myfile.sqlite <<END
.separator " "
.import myfile mytable
select max(col1), avg(col1) from mytable;
END

产出

1.00567 0.248412