Update.
authorFrancois Fleuret <francois@fleuret.org>
Fri, 26 Mar 2021 17:20:03 +0000 (18:20 +0100)
committerFrancois Fleuret <francois@fleuret.org>
Fri, 26 Mar 2021 17:20:03 +0000 (18:20 +0100)
getbib.sh [new file with mode: 0755]

diff --git a/getbib.sh b/getbib.sh
new file mode 100755 (executable)
index 0000000..e7d2f18
--- /dev/null
+++ b/getbib.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Very ugly but handy stuff: loops through the bibtex keys provided as
+# arguments, and for each grabs the first bib entry that matches in
+# all the found bib files.
+
+tmp=$(mktemp /tmp/getbib.XXXXXX)
+
+while [[ "$1" ]]
+do
+    rm -f "${tmp}"
+    find -type f -name "*.bib" | while read f && [[ ! -s "${tmp}" ]]
+    do
+        sed -n '/^[ \t]*@[^{]*{'$1'/,/^[ \t]*}/p' "${f}" > "${tmp}"
+    done
+    cat "${tmp}"
+    echo
+    shift
+done
+
+rm -rf "${tmp}"