Skip to content

Instantly share code, notes, and snippets.

@rtfpessoa
Last active September 29, 2015 14:28
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 rtfpessoa/1e5cd3cd1ddaab869217 to your computer and use it in GitHub Desktop.
Save rtfpessoa/1e5cd3cd1ddaab869217 to your computer and use it in GitHub Desktop.
Line counter dummy script
#!/bin/bash
EXTENSION=$1
FILE_COUNT=0
LINE_SUM=0
for FILE in $(find . -type f -iname "*.$EXTENSION")
do
NUM_LINES=$(cat $FILE | wc -l)
NUM_LINES=${NUM_LINES%% }
NUM_LINES=${NUM_LINES## }
LINE_SUM=$((LINE_SUM + $NUM_LINES))
FILE_COUNT=$((FILE_COUNT + 1))
echo "File $FILE has $NUM_LINES lines"
done
AVERAGE_LINE_PER_FILE=$(($LINE_SUM / $FILE_COUNT))
echo "Average line count is $AVERAGE_LINE_PER_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment