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

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

perl程序中,比如统计fileA的行数,最简单的办法是?
或者用shell下的命令,最好是一个指令就能统计出来的。
wc -l
刚才问题表述不太清楚呵呵,其实是想统计非空行的个数

我现在只能在perl中用
while(<FILEA>
{
    /\S/ and $count++;
}
的办法,虽然能实现但是看起来比较麻烦呵呵
grep -v "^\s*$" ttt.pl | wc -l
@file = <FILEHANDLE>;;
$count = @file;
try:AWK

[Copy to clipboard] [ - ]
CODE:
awk '$0!~/^$/{m++}END{print m}' fileA

$number = grep { !/^\s*$/ } <FF>;;
Try perl1line:

[Copy to clipboard] [ - ]
CODE:
perl -ne 'print $. if eof' filename

awk? try:

[Copy to clipboard] [ - ]
CODE:
awk 'END{print NR}' filename

or:

[Copy to clipboard] [ - ]
CODE:
nl filename|tail -n1

Maybe it's off the topic, I just did a performance test on above methods with no blank line filtering. Just as I expected, wc is the fastest.

time perl -ne 'print $. if eof' tt
3466212
real    0m23.510s
user    0m7.120s
sys     0m1.950s

time perl -ne 'print $. if eof' tt
3466212
real    0m21.308s
user    0m6.660s
sys     0m2.000s

time awk 'END{print NR}' tt
3466212

real    0m22.699s
user    0m3.520s
sys     0m2.420s

time awk 'END{print NR}' tt
3466212

real    0m21.341s
user    0m3.810s
sys     0m2.240s

time wc -l tt
3466212 tt

real    0m18.756s
user    0m0.900s
sys     0m2.300s

time wc -l tt
3466212 tt

real    0m17.333s
user    0m1.120s
sys     0m2.150s


time nl tt|tail -n1
3466212 xxxx

real    1m2.507s
user    0m49.000s
sys     0m5.270s