linux 中如何统计每一行所占的字符长度

 

001、

[root@pc1 test3]# ls
test.txt
[root@pc1 test3]# cat test.txt    ## 测试数据
addg
ad
adfgg
d
dfg
[root@pc1 test3]# awk '{print length}' test.txt
4
2
5
1
3

 

 

002、awk

[root@pc1 test3]# ls
test.txt
[root@pc1 test3]# cat test.txt
addg
ad
adfgg
d
dfg
[root@pc1 test3]# awk -F "" '{print NF}' test.txt     ## awk实现
4
2
5
1
3

 

003、awk

[root@pc1 test3]# ls
test.txt
[root@pc1 test3]# cat test.txt       ## 测试数据
addg
ad
adfgg
d
dfg
[root@pc1 test3]# awk '{print gsub(/./,"&")}' test.txt    ## awk实现
4
2
5
1
3

 

posted @ 2022-10-14 09:41  小鲨鱼2018  阅读(1082)  评论(0编辑  收藏  举报