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 @   小鲨鱼2018  阅读(1176)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2020-10-14 linux系统中case命令的用法
2020-10-14 linux中批量创建用户脚本示例
2020-10-14 linux系统中逻辑测试语句
点击右上角即可分享
微信分享提示