Back Table of contents Index Next   BibTool Manual
Introduction
Using BibTool --- Some Instructive Examples
Extracting Entries Matching a Regular Expression

Extracting Entries Matching a Regular Expression

BibTool can be used to extract the references which fulfill certain criteria. Those criteria can be specified utilizing regular expressions.1 As a special case we can extract all entries containing a certain substring of the key:

bibtool -X tex all.bib -o some.bib

This instruction selects all entries containing the substring tex in the key. The second option -o followed by a file name specifies the destination of the output. Thus instead of writing the result to the standard output stream the result is written into this file.

Next we want to look up all entries containing a substring in some of its fields. For this purpose we search for the string in all fields first:2

bibtool -- select{"tex"} all.bib -o some.bib

Note that the comparison is not done case sensitive; however this can be customized (see page Extracting with Regular Expressions).

Finally we want to select only those entries containing the substring in anyone of certain fields. For this purpose we simply specify the names of those fields in the select instruction:

bibtool -- select{title booktitle $key "tex"} all.bib -o some.bib

This example extracts all entries containing the substring tex in the title field, the booktitle field, or the reference key.

After we have come so far we can say that the first example in this section is in fact a short version of the following command:

bibtool -- select{$key "tex"} all.bib -o some.bib

As a simple case of extraction we might want to extract all books from a bibliography. This can be done with the following command:

bibtool -- select{@book} all.bib -o some.bib

A similar method can also be applied for other entry types.


1 Those features are only usable if the regular expression library has been enabled during the configuration of BibTool---which is the default.
2 Note that some command line interpreters (e.g the UN*X shells) might need additional quoting of the select instruction since it contains special characters.



Back Table of contents Index Next   BibTool Manual
Introduction
Using BibTool --- Some Instructive Examples
Extracting Entries Matching a Regular Expression
© 1999 Gerd Neugebauer