/ Published in: Bash

The progress bar snippet found on this site was used. This counts all lines and files in working directory for specified file extension. I am no pro at bash, just a beginner. I'm sure it can be done better but still useful.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
countLines() { if [ $# -ne 1 ]; then echo "Usage: countLines <file extension>" return fi N=0 CURRENT=0 INCREMENTS=5 FILES=` find . -type f -name "*.$1" | wc -l ` FOO=">" BAR="" find . -type f -name "*.$1" -print | while read file; do LINES=` wc -l $file | awk '{print $1}' ` N=$(( $N + $LINES )) CURRENT=$(( $CURRENT + 1 )) PERCENT=$(( $CURRENT * 100 / $FILES)) if [ $(( $PERCENT - $INCREMENTS )) -gt 5 ]; then INCREMENTS=$(( $INCREMENTS + 5 )) BAR="${BAR}=" fi echo -ne "\r\t[ " echo -ne "${BAR}${FOO} ] ${PERCENT}% " if [ $CURRENT -eq $FILES ]; then echo "complete!" echo echo " File extension.... $1" echo " File count ....... $FILES files" echo " Line count ....... $N lines" echo fi done }
Comments
