Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
Unix

Journal karniv0re's Journal: Lines of Code Counter 2

Here's a quick little script that counts all the lines of code in my ColdFusion projects.

It can easily be adjusted to count other files.

#!/bin/bash

# Count lines of code starting at the parent directory

xmlfiles=`find . | grep "\.xml$"`;
cfmfiles=`find . | grep "\.cfm$"`;
cfcfiles=`find . | grep "\.cfc$"`;
jsfils=`find . | grep "\.js$"`;

total='0';

for file in $xmlfiles
do
total="$total + `wc -l $file | awk {'print $1'}`";
done

for file in $cfmfiles
do
total="$total + `wc -l $file | awk {'print $1'}`";
done

for file in $cfcfiles
do
total="$total + `wc -l $file | awk {'print $1'}`";
done

for file in $jsfiles
do
total="$total + `wc -l $file | awk {'print $1'}`";
done

echo $total | bc -q

This discussion has been archived. No new comments can be posted.

Lines of Code Counter

Comments Filter:
  • try total=$((total + `wc -l $file | awk {'print $1'}`))

    Other things:
    instead of grep try
    find . -name '*.xml'
    or even
    find . -name '*.xml' -o -name '*.cfm' -o -name '*.cfc' -o ...

    If you know that there's fewer than ~5000 files (bash's maximum # of arguments on a command line, compile-time option so YMMV) then you can pull it off in one line even:
    total=$(wc -l $(find . -name '*.xml' -o -name '*.cfm' -o -name '*.cfc' -o -name '*.js') | awk '/total$/ {print $1}')

    • by karniv0re (746499)
      Thanks Qzukk! I had originally tried bash arithmetic, but I was getting syntax errors, so I went with what I knew. :-) The find arguments are interesting as well. I imagine it's a little speedier than grepping through all the results. Your comments are appreciated!

Dealing with the problem of pure staff accumulation, all our researches ... point to an average increase of 5.75% per year. -- C.N. Parkinson

Working...