linux系统中统计每一行的字符数

1、awk命令

[root@PC3 test]# cat a.txt
dfs
dsafd
d
fgasdf
safd
ge
[root@PC3 test]# awk -F "" '{print NF}' a.txt
3
5
1
6
4
2

2、

[root@PC3 test]# cat a.txt
dfs
dsafd
d
fgasdfd
safd
ge
[root@PC3 test]# a=`awk 'END{print NR}' a.txt `
[root@PC3 test]# echo $a
6
[root@PC3 test]# for i in `seq $a`;do sed -n "$i"p a.txt | wc -c | awk '{print $0-1}';done
3
5
1
7
4
2
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14348576.html