[root@1E5BB3B8E8B51497 ~]# echo -e '1\n2\n3'
1
2
3
以下两条命令都能得到结果 6
echo -e '1\n2\n3' | awk '{for(n=1;n<=NF;n++)t[n]+=$n}END{for(n=1;n<=NF;n++)printf t[n]}'
echo -e '1\n2\n3' | awk '{sum+=$1}END{print sum}'
试验一下
echo -e '1\n2\n3' > num.txt
cat num.txt
cat num.txt | awk '{sum += $1} END {print sum}'
rm -rf num.txt
df -B 1g | grep 'disk' | awk '{print $2}' | awk '{sum+=$1}END{print sum}'