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 @ 2022-09-12 14:58  小鲨鱼2018  阅读(798)  评论(0编辑  收藏  举报