0

I'm trying to use Bibtool to exclude (filter out) a range of entries from a bibliography, based on some field criteria.

Bibtool offers the select.by.non.string rule which will cause a bibliographic entry to be excluded if it contains a certain string in one of its fields.

For example, for a given bib file with the following entries:

@misc{foo19,
  author = {Foo, John},
  title = {Travel Diary},
  year = {2019},
  publisher = {Bar Publishing}
}

@misc{smith20,
  author = {Smith, Mary},
  title = {New Years Resolutions},
  year = {2020}
  publisher = {Bar Publishing}
}

@misc{foo20,
  author = {Foo, John},
  title = {Isolation},
  year = {2020}
  publisher = {Pandemic Press}
}

and calling bibtool with the following resource file:

select.by.string.ignored {"{}"}
select.case.sensitive {off}
select.by.non.string { title "Travel Diary" }

will result in a the output excluding any entries with a title of "Travel Diary", in this case a resulting bibliography of:

@misc{smith20,
  author = {Smith, Mary},
  title = {New Years Resolutions},
  year = {2020}
  publisher = {Bar Publishing}
}

@misc{foo20,
  author = {Foo, John},
  title = {Isolation},
  year = {2020}
  publisher = {Pandemic Press}
}

So far, so good. But the behaviour becomes problematic once multiple such rules are included in the resource file. On page 34 (Section A.9.2) of the current Bibtool manual it states that

If several rules are supplied then any entry matching one of the rules is selected. Thus different rules act as alternatives.

What I expected to happen, was that whichever rule is first matched applies to that given entry, however this is not the case. If a second rule is added to the resource file, as such:

select.by.string.ignored {"{}"}
select.case.sensitive {off}
select.by.non.string { title "Travel Diary" }
select.by.non.string { title "Isolation" }

Instead of filtering out both entries containing "Travel Diary" and "Isolation" titles, it filters out NO bibliographic entries at all; the full, original input bibliography is returned with no Bibtool errors.

Furthermore, I get the same results when specifying multiple fields within even a single select.by.non.string rule.

All I want is to exclude various entries based on a list of criteria, should be a fairly trivial exercise. Is this the wrong rule / tool, am I doing it wrong ... how do others get this task done without resorting to cut and paste?

1
  • Of course the behavior does follow the manual, i.e., the first rule matches "Isolation" and the second rule matches "Travel Diary", so for both there is a rule that returns them, so both are returned. Running bibtool twice with the result of the first run with the first rule as input for the second run with the second tool could work, but of course this is impractical if you have a long list of strings you want to exclude.
    – Marijn
    May 6 '20 at 6:07
0

You can use regular expressions for this. Similar to the options for strings, there is select to include entries that match the regular expression and select.non to exclude entries that match the expression.

In regular expressions the bar | is used as the 'or' operator. In Bibtool this character needs to be escaped by a backslash, as noted in the manual on page 32.

Resource file:

select.by.string.ignored {"{}"}
select.case.sensitive {off}
select.non { title "Travel Diary\|Isolation" }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.