Last active
September 25, 2018 23:19
-
-
Save dogtopus/c6bf2f445704cd4c328a4e27befa7b1f to your computer and use it in GitHub Desktop.
Resolve DOI references and print bibliography in BibTeX format
This file contains hidden or 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 | |
if [[ $# -lt 1 ]]; then | |
echo "Usage ${0} <doi> ..." | |
exit 1 | |
fi | |
for doi in "${@}"; do | |
ref="$(curl -sSf -H 'Accept: application/x-bibtex' -L "http://dx.doi.org/${doi}")" && { \ | |
head -n1 <<< "${ref}" | egrep -q '^@[a-zA-Z]+' | |
if [[ $? != 0 ]]; then | |
echo 'WARNING:' "${doi}" 'does not look like a BibTeX entry. Manual check is recommended.' 1>&2 | |
fi | |
cat <<< "${ref}" | |
} | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment