Lots of answers, but none of them leveraging thisthis, so here is another.
null[_String] := Null
Length @ ReadList["data.txt", null @ String, NullRecords -> True]
On my system this is more than three times as fast as Rolf Mertig's CountLines
, and a lot more concise as well.
If even one Null
for every record is too much memory usage then read in blocks of e.g. 1000:
num[Longest[x__String], ___] := Length @ {x}
Tr @ ReadList["data.txt", num @@ Table[String, {1000}], NullRecords -> True]