scripts/count-lines.sh 634 B raw
1
#!/bin/sh
2
# Count non-blank lines in all .rad files, skipping tests.
3
4
dir="${1:-.}"
5
6
if [ ! -d "$dir" ]; then
7
  echo "Error: Directory '$dir' does not exist"
8
  exit 1
9
fi
10
11
echo "Counting non-blank lines in .rad files in: $dir"
12
echo "-------------------------------------------"
13
14
total=0
15
for file in $(find "$dir" -name "*.rad" -type f -not -path "*/tests/*" -not -name "tests.rad" | sort); do
16
  if [ -f "$file" ]; then
17
    count=$(grep -v '^[[:space:]]*$' "$file" | wc -l)
18
    total=$((total + count))
19
    printf "%6d  %s\n" "$count" "$file"
20
  fi
21
done
22
23
echo "-------------------------------------------"
24
printf "%6d  TOTAL\n" "$total"