tgetrefer - scholarref - tools for DOI and BiBTeX reference extraction, fetching, and parsing
 (HTM) git clone git://src.adamsgaard.dk/scholarref
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tgetrefer (1013B)
       ---
            1 #!/bin/sh
            2 # reads DOIs (without URL prefix) as stdin and returns refer(1) format references
            3 
            4 while read -r doi
            5 do
            6         curl -sLH "Accept: application/x-research-info-systems" "https://doi.org/${doi}"
            7 done | \
            8 awk '
            9 function rmlbl() {
           10         sub(/[A-Za-z][A-Za-z0-9]  - /, "");
           11 }
           12 
           13 BEGIN { delete authors[0] }
           14 
           15 /DO  - / { doi = $3 }
           16 /TI  - / { rmlbl(); title = $0 }
           17 /T2  - / { rmlbl(); journal = $0 }
           18 /PY  - / { year = $3 }
           19 /SP  - / { page = $3 }
           20 /IS  - / { issue = $3 }
           21 /VL  - / { volume = $3 }
           22 /AU  - / {
           23         rmlbl()
           24         if (length(authors) == 0) {
           25                 firstauthor = $0
           26                 sub(/,.*/, "", firstauthor)
           27         }
           28         split($0, a, /, /)
           29         gsub(/[^A-Z ]+/, ".", a[2])
           30         authors[length(authors)] = sprintf("%s %s", a[2], a[1])
           31 }
           32 
           33 END {
           34         printf "%%L %s%d\n", firstauthor, year
           35         for (i in authors)
           36                 printf "%%A %s\n", authors[i]
           37         printf "%%T %s\n", title
           38         printf "%%J %s\n", journal
           39         printf "%%D %d\n", year
           40         printf "%%N %s", volume
           41         if (issue)
           42                 printf "(%s)", issue
           43         printf "\n%%P %s\n", page
           44         if (doi)
           45                 printf "%%O https://doi.org/%s\n", doi
           46 }
           47 '