Debian Codegraph @

texmf-dist/source/bibtex/bibtools/bibkey

raw
1 #!/bin/csh -f
2 #
3 # bibkey - look for a word in the keyword field
4 # in the references in a BiBTeX file. A restricted form of looktex, in
5 # that bibkey only looks at "keyword" fields of the entries.
6 #
7 # David Kotz ([email protected])
8 #
9 # usage:
10 # bibkey keyword file...
11 #
12 # Warning: Any characters in keyword that have meanings in regexps
13 # used by either sed or egrep must be escaped with a \ (the most
14 # likely occurrence might be \ itself: use \\). Case is ignored in
15 # the search.
16 #
17 # Multiple keywords may be specified with an egrep alternation format:
18 # eg bibkey 'jones|smith' foo.bib
19 #
20 # Actually, any egrep expression is allowed.
21 # Be sure to quote it properly.
22 #
23
24 set L=~/lib
25
26 if ($#argv < 2) then
27 echo usage: bibkey keyword 'file...'
28 exit 1
29 endif
30
31 set keyword=`echo "$1" | tr A-Z a-z`
32 shift
33
34 set script=/tmp/bibkey$$
35 onintr cleanup
36
37 # Search for the keyword and get a script for extracting the
38 # references:
39 # Cat the files
40 # Strip comment lines and comments on lines
41 # Translate to lower case (needs to precede sed and egrep)
42 # Extract the keyword entries, plus number for lines with @
43 # Search for the keyword
44 # Convert this output into a sed script
45 cat $* \
46 | sed -e 's/^%.*//' -e 's/\([^\\]\)%.*/\1/' \
47 | tr A-Z a-z \
48 | sed -n -f $L/bibkey.sed \
49 | egrep '^[0-9]*$|'"($keyword)" \
50 | awk -f $L/bibkey.awk > $script
51
52 # Now have sed print out the correct entries:
53 cat $* | sed -n -f $script
54
55 cleanup:
56 rm -f $script