number_length.sh
#!/bin/bash
n=$(wc -l /root/1.txt | awk '{print $1}')
sum=0
for i in $(seq 1 $n)
do
line=$(sed -n "$i"p /root/1.txt)
n_n=$(echo $line | sed s'/[^0-9]//'g | wc -L)
sum=$[$sum+$n_n]
done
echo "sum:$sum"
验证:
[root@logstash ~]# sh number_length.sh
sum:8
[root@logstash ~]# cat 1.txt
a b12cdefghaaaaa
bbbb34bbbbbbbbb
fafdaf45adfafda
afadfvcx67vcvxc
[root@logstash ~]#