统计一个文件行数的最简单方法是什么?

and if run with filtering, then awk is the winner.

time grep -v "^\s*$" tt | wc -l
3466212

real    0m22.181s
user    0m7.720s
sys     0m4.600s

time grep -v "^\s*$" tt | wc -l
3466212

real    0m21.869s
user    0m7.830s
sys     0m4.890s

time perl -ne '$count++ if ! /^\s*$/; print "$count\n" if eof' tt
3466212

real    0m22.741s
user    0m8.620s
sys     0m1.990s

time perl -ne '$count++ if ! /^\s*$/; print "$count\n" if eof' tt
3466212

real    0m23.379s
user    0m8.830s
sys     0m2.050s


time awk '$0!~/^\s*$/{m++}END{print m}' tt
3466212

real    0m19.938s
user    0m5.000s
sys     0m2.430s

time awk '$0!~/^\s*$/{m++}END{print m}' tt
3466212

real    0m20.747s
user    0m4.980s
sys     0m2.220s
well done~
o my god!
关键是效率呀