题解 | #打印每一行出现的数字个数#
打印每一行出现的数字个数
http://www.nowcoder.com/practice/2d2a124f98054292aef71b453e705ca9
awk代码
awk '
{
split($0,a,"")
cnt = 0
n = length(a)
for (i = 0; i < n; i++) {
if (a[i] == 1 || a[i] == 2 || a[i] == 3 || a[i] == 4 || a[i] == 5) cnt++
}
print("line"NR, "number:", cnt)
sum += cnt
}
END { print("sum is " sum) }
'