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