awk '{
BEGIN{stat1}
BEGIN{stat2}
pattern1{action1}
pattern2{action2}
...
patternn{actionn}
{默认动作,无条件,始终执行}
END{stat1}
END{stat2}
}'
awk 'BEGIN{
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
{
tarr[i,j]=i*j;
print i,"*",j,"=",tarr[i,j];
}
}
}'
# awk 打印 99乘法表
awk 'BEGIN{
for(i=1;i<10;i++)
{
for(j=1;j<=i;j++)
{
printf "%d%s%d%s%d ",j,"*",i,"=",i*j;
}
printf "
"
}
}'
# awk 浮点计算
aa=20645323448563562456
bb=1024532542341354
awk -v m1=$aa -v m2=$bb 'BEGIN{
num = m1/m2;
print m1;
print m2;
print num;
printf "%.9f
", num;
}'
# 计算器
firstNum=20645
secondNum=102.4
ss=`awk -v m1=$firstNum -v m2=$secondNum 'BEGIN{num = m1/m2; printf "%.9f
", num;}'`
echo $ss
201.611328125