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
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律