Update.
[scripts.git] / getbib.sh
1 #!/bin/bash
2
3 # Very ugly but handy stuff: loops through the bibtex keys provided as
4 # arguments, and for each grabs the first bib entry that matches in
5 # all the found bib files.
6
7 tmp=$(mktemp /tmp/getbib.XXXXXX)
8
9 while [[ "$1" ]]
10 do
11     rm -f "${tmp}"
12     find -type f -name "*.bib" | while read f && [[ ! -s "${tmp}" ]]
13     do
14         sed -n '/^[ \t]*@[^{]*{'$1'/,/^[ \t]*}/p' "${f}" > "${tmp}"
15     done
16     cat "${tmp}"
17     echo
18     shift
19 done
20
21 rm -rf "${tmp}"