Skip to content

Instantly share code, notes, and snippets.

@Alxandr
Last active October 5, 2015 19:47
Show Gist options
  • Save Alxandr/2865430 to your computer and use it in GitHub Desktop.
Save Alxandr/2865430 to your computer and use it in GitHub Desktop.
A short shell-script that is used to count lines of files given one or more file-sufixes.
#!/bin/bash
#Example use: count_files.sh cs xml // counts lines in *.cs and *.xml recursivly.
set -e
FILES="$@"
for f in $FILES; do
echo -ne "*.$f "
find . -name "*.$f" |
while read file; do
wc -l "$file" |
awk '{print $1}';
done |
awk 'BEGIN { l = 0; s = 0 } {l+=$1} {s+=1} END {print s, l}'
done |
awk '{f+=$2} {l+=$3} {print $1.":\n Files:", $2."\n Lines:", $3."\n"} END {print "\n=================\n\nTotal:\n Files:",f,"\n Lines:",l}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment