linux 系统中 wc命令

 

001、wc -c 命令: 统计字符数

root@PC1:/home/req/input/test# ls
a.txt
root@PC1:/home/req/input/test# cat a.txt             ## 测试文件
aa bb
cc dd ee
ff
root@PC1:/home/req/input/test# wc -c a.txt           ## wc -c统计字符数, 统计包括空格和末尾的换行符
18 a.txt

 

 

统计每行的字符数:

复制代码
root@PC1:/home/req/input/test# ls
a.txt
root@PC1:/home/req/input/test# cat a.txt               ## 测试文件
aa bb
cc dd ee
ff
root@PC1:/home/req/input/test# for i in $(seq $(sed -n "$=" a.txt)); do sed -n "$i"p a.txt | wc -c; done    ## 利用循环结构统计每一行的字符数
6
9
3
复制代码

 

 

002、wc -w命令统计单词的数目

root@PC1:/home/req/input/test# ls
a.txt
root@PC1:/home/req/input/test# cat a.txt              ##  测试文件 
aa bb
cc dd ee
ff
root@PC1:/home/req/input/test# wc -w a.txt            ## 统计文本的单词数目
6 a.txt

 

 

003、统计每行的单词数目

复制代码
root@PC1:/home/req/input/test# ls
a.txt
root@PC1:/home/req/input/test# cat a.txt                                      ## 测试数据
aa bb
cc dd ee
ff
root@PC1:/home/req/input/test# for i in $(seq $(sed -n "$=" a.txt)); do sed -n "$i"p a.txt | wc -w; done   ## 利用循环结构输出每行的单词数目
2
3
1
复制代码

 

 

 

004、wc -l 输出行数

root@PC1:/home/req/input/test# ls
a.txt
root@PC1:/home/req/input/test# cat a.txt
aa bb
cc dd ee
ff
root@PC1:/home/req/input/test# wc -l a.txt
3 a.txt

 

 

005、wc -L 输出最长行的长度

root@PC1:/home/req/input/test# ls
a.txt
root@PC1:/home/req/input/test# cat a.txt            ## 测试文件
aa bb
cc dd ee
ff
root@PC1:/home/req/input/test# wc -L a.txt          ## 输出最长行的长度
8 a.txt

 

posted @   小鲨鱼2018  阅读(829)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示