[zheng@localhost ~]$ cat score.txt ngsan 80 lisi 81.5 wangwu 93 zhangsan 85 lisi 88 wangwu 97 zhangsan 90 lisi 92 wangwu 88 wangwu 99
[zheng@localhost ~]$ awk 'BEGIN{print "name average total"}{a[$1]+=$2;b[$1]++};END{for(i in a)print i "\t"a[i]/b[i]"\t"a[i]}' score.txt | column -t name average total zhangsan 87.5 175 wangwu 94.25 377 ngsan 80 80 lisi 87.1667 261.5
二、求100以内的质数
#!/bin/bash # 求100以内的质数 #declare -i i=1 i=1 while (( i<=100 )) do ret=1 for ((j=2;j<i;j++)) do # if (( i%j == 0));then if [ $(( i%j )) -eq 0 ];then ret=0 break fi done if [ $ret -eq 1 ];then echo "$i" fi # 以下六种运算方式都可以使用 # (( i=i+1 )) i=$[i+1] # i=$((i+1))
# let i=i+1
# let i++
# i=`expr $i + 1` # 下面这行中的i需要declare为int #i=$i+1 done
for 循环
#!/bin/bash for ((i=1;i<100;i++)) do ret=1 for ((j=2;j<i;j++)) do if (( i%j == 0 ));then ret=0 break fi done if ((ret==1));then echo $i fi done
cat /proc/sys/kernel/random/uuid | tr -d '-'2346e35abbf1421e9ad25ce1996f26df
原文链接:https://www.f2er.com/bash/390788.html