WORLD'S WORST SOFTWARE
Software by jason, for jason.
Software by jason, for jason.
Home
About
Articles
Resume
Contact
Software
iPlaylist CopierJava Libraries
ItunesUtilitiesScripts
Bash Scripts
File Size File Size Test Free Space Line Counter List Copy MD5 Tool OS X Rotate Logs Rename It SnapshotPHP Scripts
Write Variable To File WWS MailerJavascript Scripts
WWS Background ScalerInteresting People
Admins
Phil GlocknerDesigners
Tonya Browning Catherine Chu Justin Cox Richard Georges Stephen Gray Jonathan Horak Justin Kiehl Andrea Spencer MeatheadDevelopers
Chris Austin Joost van Dongen Noah Figg Rick Hogge John Quarles Wayne Rittiman Joe Rivera Brent Schneeman David Scott Andy Skelton Pavan TumatiLine Counter
The Line Counter bash script counts lines of code in your source code.
Features
- Does not count comment lines
- Does not count whitespace lines
- Displays total line count
Dependencies
bash, test, find, cat, grep, wc, echo
Download
linecounter.sh [1.37 KB]
The Script
#!/bin/bash
########################################################################
#
# linecounter.sh - source code line counting script
# written by Jason Baker (http://www.worldsworstsoftware.com)
#
########################################################################
#
# UPDATES:
# 2006/10/25
# - updated usage info
# 2006/9/14
# - initial version
#
########################################################################
if test -z $1
then
echo "linecounter.sh is a line counting script"
echo
echo "USAGE:"
echo " linecounter.sh PATH"
echo
echo "ARGUMENTS:"
echo " PATH - the path to find files to count lines for"
exit
fi
totallines=0
#make for's argument seperator newline only
IFS=$'\n'
for file in `find "$1" -type f`
do
echo -n "$file "
#cat echoes the file
#the first grep command filters lines without alphanumeric characters
# .. which is probably a decent way to determine a line of code
# .. it will at least filter whitespace lines, and empty lines with brackets
#the second grep command filters lines that start with a * or # or // or /*
#the wc command counts the lines (we could also use -c on grep for efficiency..)
filelines=`cat "$file" | grep -e [[:alnum:]] | grep -v "^[[:space:]]*[\*|#|//|/\*]" | wc -l`
echo $filelines
let totallines=$totallines+$filelines
done
echo "Total Lines $totallines"
########################################################################
#
# linecounter.sh - source code line counting script
# written by Jason Baker (http://www.worldsworstsoftware.com)
#
########################################################################
#
# UPDATES:
# 2006/10/25
# - updated usage info
# 2006/9/14
# - initial version
#
########################################################################
if test -z $1
then
echo "linecounter.sh is a line counting script"
echo
echo "USAGE:"
echo " linecounter.sh PATH"
echo
echo "ARGUMENTS:"
echo " PATH - the path to find files to count lines for"
exit
fi
totallines=0
#make for's argument seperator newline only
IFS=$'\n'
for file in `find "$1" -type f`
do
echo -n "$file "
#cat echoes the file
#the first grep command filters lines without alphanumeric characters
# .. which is probably a decent way to determine a line of code
# .. it will at least filter whitespace lines, and empty lines with brackets
#the second grep command filters lines that start with a * or # or // or /*
#the wc command counts the lines (we could also use -c on grep for efficiency..)
filelines=`cat "$file" | grep -e [[:alnum:]] | grep -v "^[[:space:]]*[\*|#|//|/\*]" | wc -l`
echo $filelines
let totallines=$totallines+$filelines
done
echo "Total Lines $totallines"
© 2006, 2007 Jason Baker