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

时间:2022-01-06 10:25:03

I have some data that looks like this:

我有一些看起来像这样的数据:

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

How can I get compute some statistics on these numbers? I would like to get things like min, max, avg, stddeviation for each of the columns.

如何计算这些数字的一些统计数据?我希望得到每个列的min,max,avg,stddeviation等内容。

Ideally it would be something like awk-like, and included in standard linux distributions.

理想情况下它会像awk一样,并包含在标准的Linux发行版中。

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

1 个解决方案

#1


2  

Why don't you use a database:

为什么不使用数据库:

first, add column names to your file:

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

sed -i 'i1col0 col1 col2 col3 col4' myfile

Then, create a database and output some stats:

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

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

Outputs

输出

1.00567 0.248412

#1


2  

Why don't you use a database:

为什么不使用数据库:

first, add column names to your file:

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

sed -i 'i1col0 col1 col2 col3 col4' myfile

Then, create a database and output some stats:

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

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

Outputs

输出

1.00567 0.248412