BibGrep
About
BibGrep is designed to filter BibTeX files, performing filtering on entries in the same manner grep filters lines. It was designed to identify items in large bibliographies that are missing fields, or have certain spelling variations, but is also useful to list output and produce summaries.
BibGrep is written in ruby, and relies on the bibtex-ruby gem. Notably, it’s unaffiliated with this offering (apologies for using the same name, guys).
Download
Bibgrep is distributed via ruby gems, so you simply need to run gem install bibgrep.
The source code is available from the bibgrep git page.
Using BibGrep
BibGrep has been designed with a similar interface to grep— provide some BibTeX, flags, and patterns. Because BibTeX is much richer than raw text, the pattern format is defined in terms of the bibtex keys, of the format key=pattern. BibTeX data can be loaded from stdin or from one or more files.
Output is defined by a series of flags. It’s possible to output valid BibTeX for re-use using -r, or to specify which fields are output (in a more grep-like manner) using -o=field,field,field. If no output options are given at all, the default is to output valid BibTeX.
Examples
Cleaning Comments from BibTeX
Used without options, BibGrep will output raw BibTeX and skip over comments, so it can be used to wipe comments from a file:
$ bibgrep refs.bib > refs_clean.bib
Finding All Entries with a Keyword
This uses a simple search over the comment fields, and lists only the keys for each. Filenames will be printed due to the use of multiple files.
$ bibgrep -wi -okey comment="useful" refs1.bib refs2.bib
Validating BibTeX Files
This will not output anything other than validation messages for its input files. Note the use of -F to suppress filenames when using multiple input files.
$ bibgrep -Fo refs1.bib refs2.bib refs3.bib
Help Reference
$ bibgrep -h
BibGrep v0.1.5 (11-04-13)
USAGE: ./bibgrep [-FLAGS] [-oFIELD] [-o=FIELD[,FIELD2[,...]]] [+FIELD[=RX] [+FIELD[=RX] [...]]] [FILE [FILE [...]]
Where...
FIELD : A BibTeX key to match on.
RX : Regex to match against the field. Omitting
a pattern means we use the default, /.+/
FILE : The BibTeX file(s) to parse. If your filename
begins with a dash, prefix the argument with
two dashes thus: 'lsbib -- -.bib'
FIELD : One of BibTeX's field names or one of 'key', 'type'.
Not case-sensitive.
FLAGS : A string containing some of the options below.
Default is -rw.
-f : Output filename (default if multiple files used)
-F : Suppress filename output with multiple files.
-p : Suppress placeholders for empty fields
-r : Output BibTeX (Cannot be used with -o)
-o : Specify output fields (o[=]field[,field[,field]])
-s : Specify field separator (s[=]sepstring). Default is ': '.
-v : Invert match
-i : Case-insensitive regex
-e : Extended regex
-m : Multi-line regex
-c : Process comment types
-w : Suppress BibTeX validity warnings
-V : Verbose (list conditions)
-h : Output help
NB: If no files are given, I will read from stdin.