tadd script to parse references from bibliography - scholarref - tools for DOI … | |
git clone git://src.adamsgaard.dk/scholarref | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 35e9fa3443bfcd8066f13e76eb2638a3c4b62a10 | |
parent 1dfd14081d8726f3c4f856771135c55f365ff259 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Wed, 15 Sep 2021 14:27:06 +0200 | |
add script to parse references from bibliography | |
Diffstat: | |
A parseref | 73 +++++++++++++++++++++++++++++… | |
1 file changed, 73 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/parseref b/parseref | |
t@@ -0,0 +1,73 @@ | |
+#!/bin/sh | |
+set -e | |
+ | |
+die() { | |
+ printf '%s\n' "$1" >&2 | |
+ exit 1 | |
+} | |
+ | |
+get_citation() | |
+{ | |
+ awk -v id="$1" ' | |
+ function getval(str) { | |
+ sub(/.*= *{*/, "", str) | |
+ sub(/},*$/, "", str) | |
+ gsub(/[{}]/, "", str) | |
+ return str | |
+ } | |
+ | |
+ { | |
+ if (match(tolower($0), tolower(id))) | |
+ found = 1 | |
+ if (found) { | |
+ if (match(tolower($0), /author *=/)) | |
+ author = getval($0) | |
+ else if (match(tolower($0), /year *=/)) | |
+ year = getval($0) | |
+ else if (match(tolower($0), /title *=/)) | |
+ title = getval($0) | |
+ else if (match(tolower($0), /journal *=/)) | |
+ journal = getval($0) | |
+ else if (match(tolower($0), /volume *=/)) | |
+ volume = getval($0) | |
+ else if (match(tolower($0), /number *=/)) | |
+ number = getval($0) | |
+ else if (match(tolower($0), /pages *=/)) | |
+ pages = getval($0) | |
+ else if (match(tolower($0), /doi *=/)) | |
+ doi = getval($0) | |
+ else if (match($0, /^ *} *$/)) { | |
+ found = 0 | |
+ sub(/--/, "–", pages) | |
+ split(author, authors, / +and +/) | |
+ nauthors = length(authors) | |
+ for (i = 1; i <= nauthors; i++) { | |
+ printf "%s", authors[i] | |
+ if (i < nauthors - 1) | |
+ printf ", " | |
+ else if (i == nauthors - 1) | |
+ printf " and " | |
+ } | |
+ printf " %d “%s”. %s", year, title… | |
+ if (length(volume) > 0) | |
+ printf " %s", volume | |
+ if (length(number) > 0) | |
+ printf "(%s)", number | |
+ if (length(pages) > 0) | |
+ printf ", %s.", pages | |
+ if (length(doi) > 0) | |
+ printf " doi: %s", doi | |
+ printf "\n" | |
+ } | |
+ } | |
+ } | |
+ ' "$BIB" | |
+} | |
+ | |
+if [ $# -lt 1 ]; then | |
+ while read -r id; do | |
+ get_citation "$id" | |
+ done | |
+else | |
+ get_citation "$@" | |
+fi |