Update.
[scripts.git] / getbib.sh
1 #!/bin/bash
2
3 # Any copyright is dedicated to the Public Domain.
4 # https://creativecommons.org/publicdomain/zero/1.0/
5
6 # Written by Francois Fleuret <francois@fleuret.org>
7
8 # Very ugly but handy stuff: loops through the bibtex keys provided as
9 # arguments, and for each grabs the first bib entry that matches in
10 # all the found bib files.
11
12 tmp=$(mktemp /tmp/getbib.XXXXXX)
13
14 while [[ "$1" ]]
15 do
16     rm -f "${tmp}"
17     find -type f -name "*.bib" | while read f && [[ ! -s "${tmp}" ]]
18     do
19         sed -n '/^[ \t]*@[^{]*{'$1'/,/^[ \t]*}/p' "${f}" > "${tmp}"
20     done
21     cat "${tmp}"
22     echo
23     shift
24 done
25
26 rm -rf "${tmp}"