2019-02-11 14:37:48 -08:00
#!/bin/bash
2020-02-13 12:11:29 -08:00
if [ " $1 " = = "-h" ] ; then
echo "
2023-05-15 10:49:24 -04:00
spdf - search for a doi within a pdf. If found, print the doi and then use sdoi.sh to query pubmed and append a bibtex entry with the pdf to your local bib database file
2020-02-13 12:11:29 -08:00
usage:
2021-05-29 08:19:30 -04:00
spdf.sh file.pdf
2020-02-13 12:11:29 -08:00
depends:
pdftotext - from ghostscript or poppler or texlive ?
defaults:
2023-05-15 10:49:24 -04:00
See sdoi.sh
2020-02-13 12:11:29 -08:00
"
exit 0
fi
2019-02-11 14:37:48 -08:00
2021-05-04 19:23:54 -07:00
set -e #exit if an error
# set -v -x -e #debugging
2019-02-11 14:37:48 -08:00
#Setup defaults
fn = $1
#try to extract doi from pdf and retrieve a pubmed id
2020-02-13 12:11:29 -08:00
#for 'DOI:' syntax
2021-04-08 20:52:17 -07:00
# search for doi string between first page last page 10
doi = $( pdftotext -q -f 1 -l 10 $fn - | grep -iE "doi:? ?/?10\." --max-count= 1 | tr [ :upper:] [ :lower:] | sed -E "s|.*doi:? ?/?(10.+)|\1|" )
2021-03-30 00:37:43 -07:00
2020-02-13 12:11:29 -08:00
#for 'https://doi.org' syntax
if [ -z " $doi " ] ; then
2021-04-08 20:52:17 -07:00
doi = $( pdftotext -q -f 1 -l 1 $fn - | grep -iE "doi\.org/10\." --max-count= 1 | tr [ :upper:] [ :lower:] | sed -E "s|.+doi\.org/(10.+)|\1|" )
2020-02-13 12:11:29 -08:00
fi
2019-02-11 14:37:48 -08:00
if [ -z " $doi " ] ; then
echo "doi not found"
exit 1
2023-05-15 10:49:24 -04:00
else
echo $doi
2019-02-11 14:37:48 -08:00
fi
2021-05-04 19:23:54 -07:00
sdoi.sh $doi $fn
2020-02-13 12:11:29 -08:00