Questions tagged [line-count]

76 questions
1278
votes
44 answers

How to get line count of a large file cheaply in Python?

How do I get a line count of a large file in the most memory- and time-efficient manner? def file_len(filename): with open(filename) as f: for i, _ in enumerate(f): pass return i + 1
SilentGhost
  • 307,395
  • 66
  • 306
  • 293
1002
votes
17 answers

Count number of lines in a git repository

How would I count the total number of lines present in all the files in a git repository? git ls-files gives me a list of files tracked by git. I'm looking for a command to cat all those files. Something like git ls-files | [cat all these files] |…
Dogbert
  • 212,659
  • 41
  • 396
  • 397
816
votes
23 answers

Can you get the number of lines of code from a GitHub repository?

In a GitHub repository you can see “language statistics”, which displays the percentage of the project that’s written in a language. It doesn’t, however, display how many lines of code the project consists of. Often, I want to quickly get an…
Hubro
  • 56,214
  • 69
  • 228
  • 381
112
votes
10 answers

Eclipse count lines of code

I've tried the Metrics plugin and although it's nice and all, it's not what my boss is looking for. It counts a line with just one } as a line and he doesn't want that to count as "its not a line, its a style choice". I also need to generate some…
confusified
  • 2,320
  • 7
  • 22
  • 29
34
votes
5 answers

(Python) Counting lines in a huge (>10GB) file as fast as possible

I have a really simple script right now that counts lines in a text file using enumerate(): i = 0 f = open("C:/Users/guest/Desktop/file.log", "r") for i, line in enumerate(f): pass print i + 1 f.close() This takes around 3 and a half minutes…
Adrienne
  • 465
  • 1
  • 4
  • 6
27
votes
9 answers

Fastest way to find the number of lines in a text (C++)

I need to read the number of lines in a file before doing some operations on that file. When I try to read the file and increment the line_count variable at each iteration until I reach EOF. It was not that fast in my case. I used both ifstream and…
systemsfault
  • 15,207
  • 12
  • 59
  • 66
25
votes
6 answers

Is there a way in Matlab to determine the number of lines in a file without looping through each line?

Obviously one could loop through a file using fgetl or similar function and increment a counter, but is there a way to determine the number of lines in a file without doing such a loop?
robguinness
  • 16,266
  • 14
  • 55
  • 65
13
votes
3 answers

GIT contribution per author (lines)

I'm trying to print the per-line contribution of each author to a Git repository. For that, I use the following command, adapted from How to count total lines changed by a specific author in a Git repository? git ls-tree -r -z --name-only HEAD --…
morne
  • 4,035
  • 9
  • 50
  • 96
11
votes
2 answers

D2010 compiled line count discrepancy

When building a project there are two places where source line count is reported: On the compile progress dialog Under Project | Information In Delphi 2007 these two numbers were identical for the project we are building. In Delphi 2010 these two…
user265474
10
votes
4 answers

Why does line count change so much from D2007 to D2010?

Our app at work is a huge project with over 3000 units, weighing in about 3.5 million lines of code. ...or at least it was when we were compiling it under D2007. We recently updated to D2010, and now if we run a full build, the line count finally…
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
9
votes
1 answer

Count number of lines displayed (not newlines) in an HTML textarea without jQuery?

Possible Duplicate: How to get number of rows in