Skip to content

Instantly share code, notes, and snippets.

@alco
Created March 22, 2012 22:20
Show Gist options
  • 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
@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