1 #!/bin/sh 2 #------------------------------------------------------------------------------- 3 # isi2bib -- Script to convert ISI format to BibTeX 4 # cb2Bib Tools 5 # 6 # Copyright (C) 2005-2021 by Pere Constans 7 # constans@molspaces.com 8 # 9 # Improvements and modifications: 10 # Copyright (C) 2009 by Filippo Rusconi 11 # rusconi@mnhn.fr 12 # 13 # May/June 2009: 14 # - Added checks to ensure that the used commands are available on 15 # system. 16 # - Make use of mktemp to create a temp directory. 17 # 18 # See LICENSE file that comes with this distribution 19 # 20 # Usage: isi2bib input_isi output_bib 21 #------------------------------------------------------------------------------- 22 # Using isi2xml and xml2bib utilities from: 23 # http://bibutils.refbase.org/ 24 #------------------------------------------------------------------------------- 25 26 #------------------------------------------------------------------------------- 27 # Init variables 28 #------------------------------------------------------------------------------- 29 # Modify accordingly 30 #isi2xml=/usr/local/bin/isi2xml 31 #xml2bib=/usr/local/bin/xml2bib 32 isi2xml=isi2xml 33 xml2bib=xml2bib 34 isi2xml_flags="-u" 35 xml2bib_flags="-sd -b" 36 #------------------------------------------------------------------------------- 37 38 # Immediately check that the needed programs are there: 39 "${isi2xml}" --version > /dev/null 2>&1 40 41 if [ "$?" != "0" ] 42 then 43 echo "Program ris2xml (suite bibutils) is required." 44 echo "Set it in your path, and/or modify $0 accordingly." 45 echo "Ending processing." 46 exit 1 47 fi 48 49 "${xml2bib}" --version > /dev/null 2>&1 50 51 if [ "$?" != "0" ] 52 then 53 echo "Program xml2bib (suite bibutils) is required." 54 echo "Set it in your path, and/or modify $0 accordingly." 55 echo "Ending processing." 56 exit 1 57 fi 58 59 # Make sure we trap errors (we put that after the tests above because 60 # we need the tests to fail, in case, without exiting immediately). 61 set -e 62 63 # Getting filenames from command line 64 echo "cb2Bib Tools: Script to convert ISI format to BibTeX" 65 echo "" 66 echo "It uses external package bibutils from" 67 echo "http://bibutils.refbase.org/" 68 echo "" 69 if test "$#" != 2; then 70 cat <<EOF 71 Usage: $0 input_isi output_bib 72 EOF 73 exit 2 74 fi 75 76 # Create temporary directory 77 # Note that we use the mktemp utility that ensures that 78 # we do not overwrite any preexisting directory 79 tmp_dir=$(mktemp -d --tmpdir c2b_tools_tmp.XXXXXXXX) 80 81 # Setting files 82 isi="$1" 83 bib="$2" 84 work_dir="$PWD" 85 86 # Preparing temporary files 87 cp "$isi" "${tmp_dir}"/c2b_tmp.isi 88 cp "$isi" "${tmp_dir}"/c2b_tmp.bib 89 90 # bibutils procedure 91 cd "${tmp_dir}" 92 "${isi2xml}" $isi2xml_flags c2b_tmp.isi > c2b_tmp.xml 93 "${xml2bib}" $xml2bib_flags c2b_tmp.xml | sed 's%^ISSUE=%NUMBER=%g' > c2b_tmp.bib 94 95 # Clean up 96 cd "${work_dir}" 97 cp "${tmp_dir}"/c2b_tmp.bib "$bib" 98 rm -rf "${tmp_dir}" 99 echo "" 100 echo "$0 ended."