getbib 566 B

1234567891011121314151617181920
  1. #!/bin/sh
  2. # Give this script a .pdf and it will attempt
  3. # to return a proper .bib citation via doi.
  4. # Internet connection required.
  5. if [ -f "$1" ];
  6. then
  7. # Get the doi from metadata, if not possible, get
  8. # doi from pdftotext output, if not possible, exit.
  9. doi=$(pdfinfo "$1" | grep -io "doi:.*") ||
  10. doi=$(pdftotext "$1" 2>/dev/null - | grep -o "doi:.*" -m 1) ||
  11. exit 1
  12. else
  13. # If not given file, assume argument is doi
  14. doi="$1"
  15. fi
  16. # Check crossref.org for the bib citation.
  17. curl -s "http://api.crossref.org/works/$doi/transform/application/x-bibtex" -w "\\n"