Out of curiousity I wanted to count actual lines of code in my project.
I am aware of full blown sexy free software solutions such as CLOC but I wanted a quick one-liner; without requiring any installation, plus wanted it to be portable.
After a quick bash-fu I came up with a chained Cygwin bash command which might be useful to other curious scripters, so here it is:
# method: cat the whole line | grep filter out any lines that contain // | sed delete all tab and whitespace character-only lines | sed delete all empty lines | count number of lines with wc
# count actual number of lines code for: SERVER-SIDE CODE
cat /cygdrive/d/root/Arma_3_DS/mpmissions/mgmTfA__DEVELOPMENT_DIR/server-side/mgmTfA/Serverside/mgmTfA/*.sqf | grep -v "//" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | sed '/^$/d' | wc -l
2963
# count actual number of lines code for: CLIENT-SIDE CODE
cat /cygdrive/d/root/Arma_3_DS/mpmissions/mgmTfA__DEVELOPMENT_DIR/client-side/mgmTfA.Altis/custom/mgmTfA/*.sqf | grep -v "//" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | sed '/^$/d' | wc -l
963
# count actual number of lines code for: (SERVER-SIDE) + (CLIENT-SIDE) CODE
expr `cat /cygdrive/d/root/Arma_3_DS/mpmissions/mgmTfA__DEVELOPMENT_DIR/server-side/mgmTfA/Serverside/mgmTfA/*.sqf | grep -v "//" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | sed '/^$/d' | wc -l` + `cat /cygdrive/d/root/Arma_3_DS/mpmissions/mgmTfA__DEVELOPMENT_DIR/client-side/mgmTfA.Altis/custom/mgmTfA/*.sqf | grep -v "//" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//' | sed '/^$/d' | wc -l`
3926
Now I copy & paste the last line only to a Cygwin bash shell and pressing enter gives me actual number of lines of code in my project from multiple directories and SQF files.
Question
mgm
Out of curiousity I wanted to count actual lines of code in my project.
I am aware of full blown sexy free software solutions such as CLOC but I wanted a quick one-liner; without requiring any installation, plus wanted it to be portable.
After a quick bash-fu I came up with a chained Cygwin bash command which might be useful to other curious scripters, so here it is:
Now I copy & paste the last line only to a Cygwin bash shell and pressing enter gives me actual number of lines of code in my project from multiple directories and SQF files.
Hope this helps.
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now