
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.
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
Without the calculator... (Score:2)
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}')
Re: (Score:2)