Skip to content

Instantly share code, notes, and snippets.

@alco
Created March 22, 2012 22:20
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alco/2165064 to your computer and use it in GitHub Desktop.
Save alco/2165064 to your computer and use it in GitHub Desktop.
Count the number of non-blank SLOC in an Elixir project
git ls-files | egrep '\.erl|\.ex[s]$' | xargs cat | sed '/^$/d' | wc -l
@alco
Copy link
Author

alco commented Mar 22, 2012

As of https://github.com/elixir-lang/elixir/tree/0df09a97488ceafe4133b024a79dca62c63a0165 I get 6529 lines of code. Pretty neat!

Compare that to Clojure's 72169.

@alco
Copy link
Author

alco commented Apr 1, 2013

A year later, it shows 15657 lines for code for Elixir.

@marcaddeo
Copy link

Shouldn't it be

git ls-files | egrep '\.erl|\.exs?$' | xargs cat | sed '/^$/d' | wc -l

The original only matched .exs files for me.

@stevedomin
Copy link

Same command shows 34229 lines of code for Elixir as of elixir-lang/elixir@3f9ea58

@minhajuddin
Copy link

The sed command can be changed to sed '/^$\|^\s*#/d' to ignore comment only lines

@soriyath
Copy link

@minhajuddin for some reason I get more lines with your regex ; I've also tried this one sed '/(?:^$)|(?:^\s*#)/d' which yields the same results as yours.

by piping twice, though, I get the comment lines removed, as in:
git ls-files | egrep '\.erl|\.exs?$' | xargs cat | sed '/^$/d' | sed '/^\s*#/d' | wc -l

@asakura
Copy link

asakura commented Jul 22, 2022

Same command show following line counts for different Elixir releases:

  • v1.13.4 174794
  • v1.12.3 165455
  • v1.11.4 160327
  • v1.10.4 152321
  • v1.9.4 143453
  • v1.8.2 136553
  • v1.7.4 131250
  • v1.6.6 125171
  • v1.5.3 105227
  • v1.4.5 96795
  • v1.3.4 89698
  • v1.2.6 80185
  • v1.1.1 76340
  • v1.0.5 69211
  • v0.9.3 42682
  • v0.8.3 38633
  • v0.7.2 31105
  • v0.6.0 25127
  • v0.5.0 16887

@TheArrowsmith
Copy link

Command that worked for me on MacOS to count all LoC (including ex and exs files), ignoring blank lines and comments:

git ls-files | egrep '\.erl|\.exs?$' | xargs cat | sed '/^\s*$/d' | sed '/^\s*#/d' | less

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment