Problem statement
I am looking for a way to use biber's "tool mode" to run a (CLI) command on a large .bib file in order to
- extract from it only those entries whose
keywords = {}field includes a user-definable value (such asmykeywordin the example below), and - write the resulting entries to a new
.bibfile.
Example
Imagine a .bib file with the following entries:
@article{First,
[...]
keywords = {foo, bla},
}
@article{Second,
[...]
keywords = {test, foo},
}
@article{Third,
[...]
keywords = {bla},
}
Running the "magic command" I am looking for on this .bib file would match the following entries:
- for keyword
foo:FirstandSecond - for keyword
bla:FirstandThird - for keyword
test:Second
What I am not looking for
- For a variety of reasons beyond the scope of this question, I would like to really use
biber's "tool mode" to solve this problem (rather than other tools such asbibexport,bib2bib, orbibtool). - I am looking for a solution that uses a
.conffile forbiber's "tool mode" and does not rely on any.texfile in the process.
Minimal (non-)working example
The solution to a related problem uses biber's "tool mode" to extract .bib entries by document type (rather than by matched keywords). Specifically, it seems to use a customized biber .conf file to identify entries that are not books via <per_nottype> and then exclude those from the bibliography via <map_step map_entry_null="1" />.
However, no equivalent <per_notkeyword> tag seems to exist, which is why I am guessing my solution would have to rely on some combination of map_field_set and map_field_value. The following (very ad-hoc!) example does not work as expected, though (not even for the somewhat simpler 'reverse' case it tries to implement for now, i.e., removing those entries that include the mykeyword keyword):
<?xml version="1.0" encoding="UTF-8"?>
<config>
<output_align>true</output_align>
<output_fieldcase>lower</output_fieldcase>
<sourcemap>
<maps datatype="bibtex" map_overwrite="1">
<map>
<map_step map_field_set="KEYWORDS" map_field_value="mykeyword"/>
<map_step map_entry_null="1" />
</map>
</maps>
</sourcemap>
</config>
Is there a way to amend the above .conf file for biber such as to get the desired result?
Bonus points (not really)
An added bonus would be a generic solution, which allows me to specify the target keyword(s?) as a command-line argument, while relying on only a single .conf file.
echo, for example, isn't very portable and a secure script would do more checking on arguments etc. But I don't really see why you should worry about those things so long as it works for you. – cfr Mar 22 '24 at 01:29