Skip to content

Instantly share code, notes, and snippets.

@thefotios
Created April 26, 2011 15:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefotios/942458 to your computer and use it in GitHub Desktop.
Save thefotios/942458 to your computer and use it in GitHub Desktop.
This is a way to count lines in JavaScript files. It will count the comments (multiline with /*, *, and */ as well as single line //). It then outputs the number of lines, number of comment lines, and number of code lines
printf "%25s %6s %6s %10s\n" "Filename" "Lines" "Code" "Comments" && \
find -name "*.js" -exec awk ' \
/^[ \t]*([\/]*\*|\/\/)/ {comments++} \
/^[ \t]*$/ {blank++} \
END{printf "%25s %6s %6s %10s\n",FILENAME,FNR,FNR-comments-blank,comments} \
' {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment