shell之awk面试小案例

[root@chavinking mnt]# cat textfile

chavinking 1 2 3 4 5 6

nope 1 2 3 4 5 6

[root@chavinking mnt]# cat textfile | awk '{for(i=1;i<=$NF+1;i++){sum=sum+$i} {print $1" "sum;sum=0}}'

chavinking 21

nope 21

[root@chavinking mnt]#

原文地址:https://www.cnblogs.com/wcwen1990/p/7601268.html