首页 > 系统相关 >linux 中如何统计每一行所占的字符长度

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

时间:2022-10-14 09:59:10浏览次数:34  
标签:字符 test3 pc1 awk linux test 长度 txt root

 

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

 

标签:字符,test3,pc1,awk,linux,test,长度,txt,root
From: https://www.cnblogs.com/liujiaxin2018/p/16790610.html

相关文章