Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 5th, 2011  |  syntax: None  |  size: 3.61 KB  |  views: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. #
  3. # File : wiley2bibtex : convert the wiley citations to bibtex
  4. #
  5.  
  6. usage ()
  7. {
  8.    echo -ne "wiley2bibtex : Convert citations from Wiley on line
  9. library to BibTeX\n"
  10.    echo -ne "Usage: wiley2bibtex inputfile outputfile\n"
  11. }
  12.  
  13. parse()
  14. {
  15.    if [ -f /usr/bin/dos2unix ] ; then
  16.        dos2unix "$1" > /dev/null 2>&1
  17.    else
  18.        echo "Could not find dos2unix. Continuing without converting"
  19.    fi
  20.  
  21.    # Check if it's downloaded from Wiley
  22.    grep "Provider: John Wiley & Sons, Ltd" "$1" > /dev/null
  23.  
  24.    if [ 0 -ne $? ]; then
  25.        echo -ne "Does not appear to be from the Wiley online library\n"
  26.        echo -ne "Misses the required Provider: header\n"
  27.        echo -ne "Exiting"
  28.        exit 1
  29.    fi
  30.  
  31.    echo -ne "@Article{" > $2
  32.  
  33.    # Get the values
  34.    TY=$(grep "TY  -" "$1" | awk 'BEGIN { FS = " - " }; { print $2 }')
  35.    TITLE=$(grep "TI  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  36. $2 }')
  37.    JOURNAL=$(grep "JO  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  38. $2 }')
  39.    VOLUME=$(grep "VL  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  40. $2 }')
  41.    ISSUE=$(grep "IS  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  42. $2 }')
  43.    PUBLISHER=$(grep "PB  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  44. $2 }')
  45.    SERIAL=$(grep "SN  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  46. $2 }')
  47.    URL=$(grep "UR  -" "$1" | awk 'BEGIN { FS = " - " }; { print $2 }')
  48.    DOI=$(grep "DO  -" "$1" | awk 'BEGIN { FS = " - " }; { print $2 }')
  49.    START_PAGE=$(grep "SP  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  50. $2 }')
  51.    END_PAGE=$(grep "EP  -" "$1" | awk 'BEGIN { FS = " - " }; { print
  52. $2 }')
  53.    YEAR=$(grep "PY  -" "$1" | awk 'BEGIN { FS = " - " }; { print $2 }')
  54.    AUTHOR_NUM=$(grep "AU  -" "$1" | wc -l)
  55.    # understand this!
  56.    for i in "$(grep "AU  -" $1 )"; do
  57.        AUTHOR=$(echo "$i" | awk 'BEGIN{FS = " - "}; { print $2}' | awk
  58. 'BEGIN {FS = ","};{print $2 " " $1 ","}')
  59.    done
  60.    AUTHOR=$(echo $AUTHOR | sed "s/\,$/./")
  61.  
  62.    # create ourselves a keyword
  63.    PRIME_AUTHOR=$(grep "AU  -" -m 1 $1 | awk 'BEGIN{FS = " - "}; {print
  64. $2}' | awk 'BEGIN {FS = ","};{print $2}')
  65.    KEYWORD="$PRIME_AUTHOR$YEAR"
  66.  
  67.    # Start making our file!
  68.    echo -ne $KEYWORD >> $2 ; echo "," >> $2
  69.    if [ "$DOI" ] ; then
  70.        echo -ne "\tDoi = {" >> $2 ; echo -ne $DOI >> $2 ; echo "}," >>
  71. $2
  72.    fi
  73.    if [ "$AUTHOR" ] ; then
  74.        echo -ne "\tauthor = {" >> $2 ; echo -ne $AUTHOR >> $2 ; echo
  75. "}," >> $2
  76.    fi
  77.    if [ "$TITLE" ] ; then
  78.        echo -ne "\ttitle = {" >> $2 ; echo -ne $TITLE >> $2 ; echo "},"
  79. >> $2
  80.    fi
  81.    if [ "$JOURNAL" ] ; then
  82.        echo -ne "\tjournal = {" >> $2 ; echo -ne $JOURNAL >> $2 ; echo
  83. "}," >> $2
  84.    fi
  85.    if [ "$VOLUME" ] ; then
  86.        echo -ne "\tvolume = {" >> $2 ; echo -ne $VOLUME >> $2 ; echo
  87. "}," >> $2
  88.    fi
  89.    if [ "$ISSUE" ] ; then
  90.        echo -ne "\tissue = {" >> $2 ; echo -ne $ISSUE >> $2 ; echo "},"
  91. >> $2
  92.    fi
  93.    if [ "$YEAR" ] ; then
  94.        echo -ne "\tyear = {" >> $2 ; echo -ne $YEAR >> $2 ; echo "},"
  95. >> $2
  96.    fi
  97.    if [ "$URL" ] ; then
  98.        echo -ne "\turl = {" >> $2 ; echo -ne $URL >> $2 ; echo "}," >>
  99. $2
  100.    fi
  101.    if [ "$PUBLISHER" ] ; then
  102.        echo -ne "\tpublisher = {" >> $2 ; echo -ne $PUBLISHER >> $2 ;
  103. echo "}," >> $2
  104.    fi
  105.    if [ "$PAGES" ] ; then
  106.        echo -ne "\tpages = {" >> $2 ; echo -ne $START_PAGE >> $2 ; echo
  107. -ne "-" >> $2 ; echo -ne $END_PAGE >> $2 ; echo "}," >> $2
  108.    fi
  109.    echo -e "}" >> $2
  110.  
  111.    cat $2
  112.  
  113.  
  114.  
  115. }
  116. if [ $# -ne 2 ] ; then
  117.    echo "Incorrect usage"
  118.    usage
  119.    exit 1;
  120. fi
  121.  
  122. if [ ! -f "$1" ] ; then
  123.    echo "$1: No such file." 2>&1
  124.    usage                 # Print usage message and exit.
  125.    exit 2
  126. fi
  127.  
  128. parse $*
clone this paste RAW Paste Data