Jump to content
  • 0

Count Actual Lines of Code in a Project using bash


mgm

Question

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.

Hope this helps.

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...