Skip to content

Instantly share code, notes, and snippets.

@vmassuchetto
Created May 7, 2015 07:24
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 vmassuchetto/b13e42108303327e085f to your computer and use it in GitHub Desktop.
Save vmassuchetto/b13e42108303327e085f to your computer and use it in GitHub Desktop.
Shell script to count citations in TeX files
#!/bin/bash
#
# Counts the number of lines each citation appears on a tex file.
#
# Usage:
#
# ./countbib texfile.tex
#
TEXFILE=$1
BIBFILE=$(cat $TEXFILE | grep "\\\bibliography" | sed "s/.*\\\bibliography{\(.*\)}.*/\1/g")
BIBENTRIES=$(cat "${BIBFILE}.bib" | grep "^@" | sed "s/^@.*{\(.*\)[^A-Za-z0-9]/\1/g")
COUNTLIST=$(
for BIB in $BIBENTRIES; do
LINECOUNT=$(grep $BIB $TEXFILE | wc -l)
printf "%4s %s\n" $LINECOUNT $BIB
done
)
echo "$COUNTLIST" | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment