看到网上有人说用grep的方式统计行数要比wc快好多,然后还有sed和awk等,在自己机器上做了个实验,在我这几乎没啥区别,操作记录如下。
[root@test]# time wc -l test.log
2125476 access.log
real 0m11.520s
user 0m0.004s
sys 0m0.741s
[root@test]# time grep -Fc "" test.log
2125476
real 0m11.495s
user 0m0.018s
sys 0m0.820s
[root@test]# time sed -n "$=" test.log
2125476
real 0m11.675s
user 0m0.131s
sys 0m0.939s
[root@test]# time awk 'END{print NR}' test.log
2125476
real 0m12.028s
user 0m0.143s
sys 0m0.962s
呵呵,虽说没有验证成功,但是也知道了其他几种统计行数的方法
另外,有个人测试六千多万行的数据时,还是wc命令比其他命令快。
linux 统计文件的行数
最新推荐文章于 2024-11-25 14:19:28 发布