|

楼主 |
发表于 2004-6-25 17:19:12
|
显示全部楼层
问题解决了,谢谢教主帮忙,尤其下面一帖(刚开始不知为什么没有看到源码,所以让教主多晕了一次,不好意思):thank
学习心得汇报一下
用于Xgraph的数据文件格式如下:
每个文件中包含多组数据,各组之间由空行和'"数组说明' 分割开来,要求分别求出每一组中第二列的均值和标准差,拟一简单数据文件如下
[php]
[spq@localhost code]$ cat del.tr
Titletext: test for calculation
"delay for cbr
0 1
0 2
0 2
0 3
0 2
0 2
"delay for ubr
0 1
0 1
0 5
0 6
0 1
[/php]
根据各位的教导,我的脚本:
[php]
[spq@localhost code]$ cat avdelay.sh
#!/bin/bash
awk '
/^"/{if (total != 0) {print total/n; total=0; n=0 }; print $3}
/^[0-9]+/ {total = total + $2; n=n+1}
END {print total/n; }' del.tr |
awk '
BEGIN {print "Average Delay:"}
$1 ~/^[0-9]+/ {i=i+1; A=$1; print A}
$1 !~/^[0-9]+/ {printf "%s\t",$1}
END {
print "Delay Varietion (Standard Deviation of delay sample)"
nss=0;n=0;i=0
while ((getline item <"del.tr">0)) {
split (item,X)
if (X[1]~/"/) {i=i+1;if (nss!=0) {printf "\t%f\n",sqrt(nss/n); nss=0; n=0}; printf X[3]}
if (X[1]~/[0-9]+/){nss=(X[2]-A)^2+nss; n=n+1}
}
printf "\t%f\n",sqrt(nss/n)
}'
[spq@localhost code]$ ./avdelay.sh
Average Delay:
cbr 2
ubr 2.8
Delay Varietion (Standard Deviation of delay sample)
cbr 0.577350
ubr 2.227106
[/php]
最初由 home_king 发表
晕~~~我早已说过了。
ps:建议买本O'reilly的《sed与awk》来看,我当时和学bash一样,两天入门。
[php]
while( (getline item < "datafile") > 0 ){
print item
#item保存了文件输入的每一行
#当然,你也可以用split函数把它拆分为数组来细化处理
}
[/php] |
|