我有如下输入
*KEYWORD
$TIME_VALUE = 9.9999993e-004
$STATE_NO = 2
$Output for State 2 at time = 0.001
*END
$NODAL_RESULTS
$RESULT OF Resultant Displacement
721810 1.7188E-2
721812 6.1973E-2
721825 1.1481E+0
721827 1.0962E+0
721852 5.1831E-1
721854 1.3085E-2
721867 1.1077E+0
. .
. .
. .
我需要找到第 2 列中的最大值及其平均值。然后我还需要输出代表最大值的第一列中的数字。
我使用以下代码计算最大值和平均值,但是除以零。
awk: cmd. line:5: fatal: division by zero attempted
代码如下
# 1.k is the input file name.
sed -n '/^[0-9]\{1\}/p' 1.k > 2.k # delete all lines not starting with number
mv 2.k 1.k
sed -i -e '/^$/d' 1.k # delete all lines that are empty
#sed -i -e 's/^[ \t]*//;s/[ \t]*$//' 1.k
awk 'BEGIN{min=999}
{a[NR]=$0;if($2<min){min=$2;m[1]=NR;}if($2>max){max=$2;m[2]=NR;}m[2]+=$2;}
END{print "Min:"a[m[1]];
print "Max:"a[m[2]];
print "Number Of Nodes:" NR;
print "Avg:"m[3]/NR}' 1.k
有人可以帮我解决这个问题吗?
问候,