Count the number of lines in a file without reading entire file into memory?

前端 未结 15 1324
忘掉有多难
忘掉有多难 2020-12-24 01:38

I\'m processing huge data files (millions of lines each).

Before I start processing I\'d like to get a count of the number of lines in the file, so I can then indic

15条回答
  •  囚心锁ツ
    2020-12-24 02:17

    using ruby:

    file=File.open("path-to-file","r")
    file.readlines.size
    

    39 milliseconds faster then wc -l on a 325.477 lines file

提交回复
热议问题