[comp.text] Bibtex search programs ?

mccalpin@loligo (John McCalpin) (02/23/89)

Does anyone have any nice utilities for searching through Bibtex
files for keywords and such, and then displaying the results nicely?
I would like to have such a program, but I am not sure it is worth 
the effort to program it since my C is a bit weak....
----------------------   John D. McCalpin   ------------------------
Dept of Oceanography & Supercomputer Computations Research Institute
mccalpin@masig1.ocean.fsu.edu		mccalpin@nu.cs.fsu.edu
--------------------------------------------------------------------

dfk@romeo.cs.duke.edu (David F. Kotz) (02/25/89)

In article <7348@pyr.gatech.EDU>, mccalpin@loligo (John McCalpin) writes:
> Does anyone have any nice utilities for searching through Bibtex
> files for keywords and such, and then displaying the results nicely?
> I would like to have such a program, but I am not sure it is worth 
> the effort to program it since my C is a bit weak....
> ----------------------   John D. McCalpin   ------------------------
> Dept of Oceanography & Supercomputer Computations Research Institute
> mccalpin@masig1.ocean.fsu.edu		mccalpin@nu.cs.fsu.edu
> --------------------------------------------------------------------

Sure, try this:

#
# looktex - look for a keyword in the references in a BiBTeX file.
#
# David Kotz (dfk@cs.duke.edu)
#
# usage: 
#  looktex keyword file...
#
# Warning: Any characters in keyword that have meanings in regexps
# used by either sed or egrep must be escaped with a \ (the most 
# likely occurrence might be \ itself: use \\). Case is ignored in 
# the search, as well as position in the reference.
#
# Multiple keywords may be specified with an egrep alternation format:
# eg  looktex 'jones|smith' foo.bib
#
# Actually, any egrep expression is allowed. 
# Be sure to quote it properly. 
#
# BUGS: Won't notice occurrences of the  keyword on the same line as
# the @. Therefore references that have the keyword there only 
# cannot be found.
#

set L=/usr/local/public/lib

if ($#argv < 1) then
    echo usage: looktex keyword 'file...'
    exit 1
endif

set keyword=`echo $1 | tr A-Z a-z`
shift

onintr cleanup
set script=/tmp/looktex$$

# Search for the keyword and get a script for extracting the
# references:
#  Cat the files and translate to lower case
#  Strip comment lines and comments on lines
#  Search for the keyword and all @ lines
#  Extract the line number only, plus 'entry' for lines with @
#  Convert this output into a sed script
cat $* | tr A-Z a-z \
    | sed -e 's/^%.*//' -e 's/\([^\\]\)%.*/\1/' \
    | egrep -n "($keyword)"'|^[ ]*@' \
    | sed -n -e 's/:[ ]*@.*/ entry/p' -e 's/:.*//p' \
    | awk -f $L/looktex.awk > $script

# Now have sed print out the correct entries:
cat $* | sed -n -f $script 

cleanup:
rm -f $script
Department of Computer Science, Duke University, Durham, NC 27706
ARPA:	dfk@cs.duke.edu
CSNET:	dfk@duke        
UUCP:	decvax!duke!dfk