Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Re-generating reference file for Bibtex
#!/bin/bash
## this script parses *.aux files (LaTeX/bibtex temporary files) in
## the current directory, extracts cited references and re-generates
## a bibtex-file
RESULTFILE=newreferences.bib
handle_outputfile_found()
{
echo
echo "ERROR: I already found file \"${RESULTFILE}\". To prevent data loss, I quit now."
echo
exit 1
}
handle_no_auxfile_found()
{
echo
echo "ERROR: I found no file with an \".aux\" extension in the current folder."
echo
exit 2
}
handle_no_bibtexfile_found()
{
echo "WARNING: I found no bibtex-file \"${1}\". Continuing ...."
}
[ -f "${RESULTFILE}" ] && handle_outputfile_found
touch "${RESULTFILE}"
#echo "Creating new output reference file: ${RESULTFILE}"
numaux=`ls -l *aux | wc -l`
[ ${numaux} -eq 0 ] && handle_no_auxfile_found
referredpapers=`grep citation *.aux | sed 's/\\\\citation{//' | sed 's/}//'| sort | uniq`
for currentref in ${referredpapers}; do
#echo "do: ${currentref}";
nextfile="${HOME}/archive/library/${currentref}.bib"
if [ -f "${nextfile}" ]; then
cat "${nextfile}" >> "${RESULTFILE}"
else
handle_no_bibtexfile_found "${nextfile}"
fi
done
echo "successfully finished writing: ${RESULTFILE}"
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.