网站首页 > 技术教程 正文
在日志分析过程中,经常会遇到文件行计数的情况。它可以帮助我们分析业务数据。
那么在Linux中如何使用linux命令行统计文件行数呢?
- 使用linux wc命令统计文件行数
wc -l test.txt
- 使用linux 管道、cat和wc命令统计文件行数
cat test.txt | wc -l
- 使用linux awk命令统计文件行数
awk 'END{print NR}' test.txt
# OR
awk '{print NR}' test.txt | tail -n1
- 使用sort命令、uniq命令和wc 命令统计文件非重复行的总数
cat test.txt | sort| uniq | wc -l
- 统计文件重复行的总数
# Sort and count the number of repetitions per row
sort test.log | uniq -c
# Number of lines with output repetition greater than 1
sort test.log | uniq -c | awk -F' ' '{if($1 > 1) { print $0 }}'
# Count total number of duplicate lines
sort test.log | uniq -c | awk -F' ' '{if($1 > 1) { print $0 }}' | wc -l
- 统计指定内容在文件中出现的次数
grep -c 'awk' test.log
# OR
grep 'awk' test.log | wc -l
- 上一篇: Linux的常用Shell命令新手入门:文件查看2
- 下一篇:已经是最后一篇了
猜你喜欢
- 2025-06-15 Linux的常用Shell命令新手入门:文件查看2
- 2025-06-15 Linux统计当前文件夹下文件数量(linux统计文件总数)
- 2025-06-15 linux中find命令根据文件名字来查找
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)