Created
January 21, 2015 09:02
-
-
Save tfrisk-old/bc7c896798f9f54c5078 to your computer and use it in GitHub Desktop.
Find count of code lines in Clojure source files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find count of code lines in Clojure source files | |
cat file.clj | grep -e '^$' -e '^;' -v | wc -l | |
# How it works? | |
# | |
# cat file.clj view file with cat command | |
# | pipe the output of cat command to the following commands | |
# grep read the input (piped cat) and match it to given regular expressions | |
# -e '^$' look for line start (^) followed by immediate end ($) -> empty line | |
# -e '^;' look for line start (^) followed by Clojure comment mark (;) | |
# -v invert all the matches to get the actual code instead of comment or empty lines | |
# | wc -l pipe the matched lines to wc command to count the lines (-l) option | |
# | |
# The command prints out an integer of counted lines | |
# | |
# Here we assume the comments always start from the very beginning of the line. | |
# This can be fixed by rewriting the second expression as | |
# | |
# -e '^\s*;' | |
# | |
# Here we are using \s* as an optional whitespace match (\s) matched 0 or more times (*) | |
# The whitespace fixed version is this | |
cat file.clj | grep -e '^$' -e '^\s*;' -v | wc -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment