Skip to content

Instantly share code, notes, and snippets.

@sepans
Created January 21, 2020 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepans/147c1261f6d536c904e6de22bd6fe021 to your computer and use it in GitHub Desktop.
Save sepans/147c1261f6d536c904e6de22bd6fe021 to your computer and use it in GitHub Desktop.
#!/bin/bash
verbose=`$( $2 = "-v" )`
verbose=0; [ "$2" == "-v" ] && verbose=1
echo "counting lines in directory: $1 params? $2, verbose: use -v? $verbose"
sum=0
for filename in `find "$1" -type f`
do
if [ $verbose = 1 ]
then
echo " lines in $filename"
fi
lineNums="$(wc -l < $filename)"
sum=`expr $sum + $lineNums`
if [ $verbose = 1 ]
then
echo "file has $lineNums lines, current sum $sum"
fi
done
echo "total number of lines: $sum"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment