看到有网上一篇博客写的
https://blog.csdn.net/hu721659947/article/details/80352003
输出数组中大于5的数,需要注意if [ $a –ge$b ]中的空格 #!/bin/bash array=(1 2 3 5 64 7 8 9 21) length=${#array[@]} for((a=0;a<$length;a++)) do if [ ${array[$a]} -ge 5 ] then echo ${array[$a]} fi done --------------------- 作者:hu721659947 来源:CSDN 原文:https://blog.csdn.net/hu721659947/article/details/80352003
使用awk一行命令即可实现:
echo ${array[@]} | awk '{split($0,a," ");for(i in a)if(a[i]>5){print a[i]}}'
cat >b<<EOF
2019-05-07_20:01:11 50
2019-05-07_20:55:12 30
2019-05-07_21:15:31 10
2019-05-07_21:23:41 40
2019-05-07_21:58:51 50
EOF
cat b | awk -F[: ] '{print $1,$4}' | awk '{a[$1]+=$2}END{for(i in a){print i,a[i]}}'
2019-05-07_20 80
2019-05-07_21 100