Skip to content

Instantly share code, notes, and snippets.

@dogtopus
Last active September 25, 2018 23:19
Show Gist options
  • Save dogtopus/c6bf2f445704cd4c328a4e27befa7b1f to your computer and use it in GitHub Desktop.
Save dogtopus/c6bf2f445704cd4c328a4e27befa7b1f to your computer and use it in GitHub Desktop.
Resolve DOI references and print bibliography in BibTeX format
#!/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