1、测试数据
[root@centos7 test3]# ls test.txt [root@centos7 test3]# cat test.txt deet dggh df
2、awk实现
[root@centos7 test3]# ls test.txt [root@centos7 test3]# cat test.txt deet dggh df [root@centos7 test3]# awk '{print length}' test.txt 4 4 2 [root@centos7 test3]# awk '{print length}' test.txt | awk 'BEGIN{sum = 0} {sum += $1} END {print sum}' 10
或者:
[root@centos7 test3]# ls test.txt [root@centos7 test3]# cat test.txt deet dggh df [root@centos7 test3]# paste -d "" -s test.txt deetdgghdf [root@centos7 test3]# paste -d "" -s test.txt | awk '{print length}' 10
原创文章,作者:Carrie001128,如若转载,请注明出处:https://blog.ytso.com/245060.html