Created
December 26, 2015 10:58
-
-
Save novoid/56f25ed1e15dc0524485 to your computer and use it in GitHub Desktop.
Re-generating reference file for BibLatex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## this script parses *.aux files (LaTeX/bibtex temporary files) in | |
## the current directory, extracts cited references and re-generates | |
## a biblatex-file | |
RESULTFILE=newreferences.bib | |
REFERENCESTMPFILE=`mktemp` | |
TMPFILE=`mktemp` | |
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 ...." | |
} | |
generate_result_file_from_referred_papers() | |
{ | |
referredpapers=`cat ${REFERENCESTMPFILE}` | |
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 | |
} | |
[ -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 citekey *bcf | sed 's/.*<bcf:citekey>//' | sed 's#</bcf:citekey>.*##' | sort | uniq > "${REFERENCESTMPFILE}"` | |
generate_result_file_from_referred_papers | |
## resolving cross references: | |
crossreferences=`grep -i crossref ${RESULTFILE} | sed 's/.*{//' | sed 's#}.*##' >> "${REFERENCESTMPFILE}"` | |
rm ${RESULTFILE} ## will be re-generated with previous citations *and* crossrefs | |
sort "${REFERENCESTMPFILE}" | uniq > ${TMPFILE} | |
mv "${TMPFILE}" "${REFERENCESTMPFILE}" | |
generate_result_file_from_referred_papers | |
rm ${REFERENCESTMPFILE} | |
echo "successfully finished writing: ${RESULTFILE}" | |
#end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment