Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 创建一个awk脚本来读取另一个awk文件的输出,并实现求和和和平均值_Linux_Shell_Awk - Fatal编程技术网

Linux 创建一个awk脚本来读取另一个awk文件的输出,并实现求和和和平均值

Linux 创建一个awk脚本来读取另一个awk文件的输出,并实现求和和和平均值,linux,shell,awk,Linux,Shell,Awk,我有一个awk脚本,我称之为random.awk,它生成一个近似正态分布的随机数 #!/usr/bin/awk -f #the sum of three uniform [-1,1] random variables is used to get the approximate normal distribution #the first argument the number of random numbers to be generated, the default is 100 #the

我有一个awk脚本,我称之为
random.awk
,它生成一个近似正态分布的随机数

#!/usr/bin/awk -f
#the sum of three uniform [-1,1] random variables is used to get the approximate normal distribution
#the first argument the number of random numbers to be generated, the default is 100
#the second argument is to get the mean value, the default is 0
#the third argument is to get the standard deviation, the default is 1

function prand(){ 
    return(((rand()*2)-1)+((rand()*2)-1)+((rand()*2)-1));
}

BEGIN{
    # establish default values
    countnumber=(length(ARGV[1])==0?100:ARGV[1]);
    meanvalue=(length(ARGV[2])==0?0.0:ARGV[2]);
    stdeviation=(length(ARGV[3])==0?1.0:ARGV[3]);

    for(i=0;i<count;i++){
    printf("%.16e\n",prand()*stdeviation+meanvalue)
    }
}
#/usr/bin/awk-f
#三个均匀[-1,1]随机变量之和用于获得近似正态分布
#第一个参数是要生成的随机数,默认值为100
#第二个参数是获取平均值,默认值为0
#第三个参数是获取标准偏差,默认值为1
函数prand(){
返回((rand()*2)-1+((rand()*2)-1+((rand()*2)-1));
}
开始{
#建立默认值
countnumber=(长度(ARGV[1])==0?100:ARGV[1]);
平均值=(长度(ARGV[2])==0?0.0:ARGV[2]);
标准偏差=(长度(ARGV[3])==0?1.0:ARGV[3]);

对于(i=0;i创建一个awk脚本,就像您刚才在生成随机值但实现均值和和和计算时所做的那样,并使用shell管道符号
|
将第一个脚本的输出传输到第二个脚本。如果您想要更多帮助,您需要在问题中提供更多信息。

awk'{sum+=$0;count++}结束{print sum,sum/count}'