54 lines
1.5 KiB
Bash
54 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# fn_dupes.sh — list \fn* footnote macros that occur more than once
|
|
# in a given chapter .tex file.
|
|
#
|
|
# Usage:
|
|
# ./fn_dupes.sh John12.tex
|
|
# ./fn_dupes.sh John*.tex # multiple files, reported separately
|
|
#
|
|
# Notes:
|
|
# - Matches \fnWord and \fnWord{...} forms alike (only the macro name
|
|
# is captured, e.g. \fnChristos -> Christos).
|
|
# - Counts are per FILE (i.e. per chapter), not across files, since
|
|
# that's the unit your glossing policy cares about. Pass one file
|
|
# at a time for a single chapter, or several for a batch report.
|
|
|
|
set -euo pipefail
|
|
|
|
if [ "$#" -lt 1 ]; then
|
|
echo "Usage: $0 <chapter.tex> [more_chapters.tex ...]" >&2
|
|
exit 1
|
|
fi
|
|
|
|
for file in "$@"; do
|
|
if [ ! -f "$file" ]; then
|
|
echo "== $file: not found, skipping ==" >&2
|
|
continue
|
|
fi
|
|
|
|
echo "== $file =="
|
|
|
|
# Extract macro names: \fnFoo -> Foo
|
|
# grep -o pulls all matches; sed strips the leading \fn
|
|
matches=$(grep -o '\\fn[A-Za-z]\+' "$file" | sed 's/^\\fn//')
|
|
|
|
if [ -z "$matches" ]; then
|
|
echo " (no \\fn macros found)"
|
|
echo
|
|
continue
|
|
fi
|
|
|
|
# Count occurrences, sort by count descending, show only count > 1
|
|
dupes=$(echo "$matches" | sort | uniq -c | sort -rn | awk '$1 > 1 {printf " %-20s x%s\n", $2, $1}')
|
|
|
|
if [ -z "$dupes" ]; then
|
|
echo " (no duplicates -- every \\fn macro used at most once)"
|
|
else
|
|
echo " Duplicates:"
|
|
echo "$dupes"
|
|
fi
|
|
|
|
echo
|
|
done
|